Dynamic Book Template

Help bring our custom Ages to life! Share tips and tricks, as well as code samples with other developers.

Re: Dynamic Book Template

Postby D'Lanor » Wed Jan 30, 2008 7:25 am

It looks for Campbravo.py because you have the AgeSDLHook turned on.

About the Python files: Try to remove the underscores. They have special meaning in Python. I guess the use of underscores in my instructions is somewhat confusing. You have to replace __YourAge__ including the underscores.

Also note that there are double underscores in the code while your files have single underscores.
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 7:34 am

@D'Lanor....I'll do that, remove the underscores......and I thought we had to have the hook on for clicking on stuff?

@Trylon....... I removed the X from clickfile............and now it won't let me click on my book at all.... :?

I'm laughing here......in a rather "oh jeez," type way.....

BRB.....I'm going to go find that large bottle of Extra Strength Tylonal that I've got laying around some where...
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 8:06 am

Okay, got something different this time:

Went in, put the X back in the clickfile command (sorry Trylon, but with out the X, the cursor won't go hot).

removed the underscoring in the python files around the file names (D'Lanor, was I suppose to remove the doubles?)

renamed the files.

repacked the pak file.

Back in Blender, changed the clickfile string to CampbravoBookGUI.
Changed the ALCscript to reflect the same.

Exported my Age. Got an Error, 'cause I forgot to reload the sound files again.
Reloaded the sound files.
Exported my Age, just fine.

loaded up Uru, linked in, walked over to my book, cursor went hot, clicked.....and nothing.

Exited Uru, opened up the log file, and this is what it said:

(01/30 10:01:38) Python file CampbravoBookGUI.py, instance not found.
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Dynamic Book Template

Postby D'Lanor » Wed Jan 30, 2008 8:17 am

Did you rename the class inside the CampbravoBookGUI.py file? It should look like this:

Code: Select all
class CampbravoBookGUI(ptModifier,):
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 8:20 am

Yep, sure did.

Here is the CampbravoBookGUI.py file:

Code: Select all
######################################
#                                    #
#  Dynamic Book Template by D'Lanor  #
#                                    #
######################################
from Plasma import *
from PlasmaTypes import *
from PlasmaNetConstants import *
import xLinkingBookDefs
import CampbravoPageDefs
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')
AgeStartedIn = None
ourBook = None
bkLinks = []
ageBooks = None
bookPages = (['welcomebk'])
class CampbravoBookGUI(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.version = '1'
        print ('__init__%s v.%s' % (self.__class__.__name__, self.version))



    def OnFirstUpdate(self):
        global AgeStartedIn
        print ('%s: OnFirstUpdate called' % self.__class__.__name__)
        AgeStartedIn = PtGetAgeName()



    def OnNotify(self, state, id, events):
        global ourBook
        global bkLinks
        print ('%s: OnNotify called' % self.__class__.__name__)
        if ((id == actClickableObject.id) and state):
            print 'Someone clicked an object'
            if (PtWasLocallyNotified(self.key)):
                print 'It was you'
                for i in range(0, len(ageBooks)):
                    if (ObjectMsg.value == ageBooks[i]):
                        print ('%s found! Start opening...' % ageBooks[i])
                        self.IOpenBook(bookPages[i], 0)
                        break
            ###################################################################################################
            # Pagenames in bookPages must be defined in the __YourAge__PageDefs file.                         #
            #                                                                                                 #
            # Opening the book with forceOwned set to 1: the code checks if the original book has been found. #
            # A player who does not own the age will not see the linking panel. By default forceOwned is off! #
            # If you need this restriction simply use: self.IOpenBook(bookPages[i], 1)                        #
            #                                                                                                 #
            # In case of multiple books the code will find any books automagically. You can add as many books #
            # as you like. Just define them in the global variables ageBooks and bookPages and make sure that #
            # their order in both variables matches.                                                          #
            ###################################################################################################
        else:
            for event in events:
                if (event[0] == PtEventType.kBook) and (PtWasLocallyNotified(self.key)):
                    print('BookNotify  event=%d, id=%d' % (event[1], event[2]))
                    if (event[1] == PtBookEventTypes.kNotifyImageLink):
                        if (event[2] >= xLinkingBookDefs.kFirstLinkPanelID):
                            print('BookNotify: hit linking panel %s' % event[2])
                            ourBook.hide()
                            for i in range(0, len(bkLinks)):
                                if (event[2] == bkLinks[i][0]):
                                    try:
                                        self.IlinkToAge(bkLinks[i][1], bkLinks[i][2], bkLinks[i][3], bkLinks[i][4])
                                    except Exception, detail:
                                        print('ERROR: Unable to initialize link - %s' % (detail))
                                    break
                    elif (event[1] == PtBookEventTypes.kNotifyShow):
                        print('Show Book')
                        PtSendKIMessage(kDisableKIandBB, 0)
                    elif (event[1] == PtBookEventTypes.kNotifyHide):
                        print('Hide Book')
                        PtSendKIMessage(kEnableKIandBB, 0)
                    elif (event[1] == PtBookEventTypes.kNotifyNextPage):
                        print('To Next Page %d' % (ourBook.getCurrentPage()))
                    elif (event[1] == PtBookEventTypes.kNotifyPreviousPage):
                        print('To Previous Page %d' % (ourBook.getCurrentPage()))
                    elif (event[1] == PtBookEventTypes.kNotifyCheckUnchecked):
                        print('Relto Page Toggled')
                    elif (event[1] == PtBookEventTypes.kNotifyClose):
                        print('Close Book')



    def IOpenBook(self, bkPages = None, forceOwned = 0):
        global ourBook
        global bkLinks
        print ('%s: IOpenBook: Page request for %s' % (self.__class__.__name__, bkPages))
        if (type(bkPages) == type(None)):
            return
        PageDef = CampbravoPageDefs.BookDef + CampbravoPageDefs.BookFont
        PageCount = xLinkingBookDefs.kFirstLinkPanelID
        bkLinks = []
        for bkPage in bkPages:
            if (not bkPage in CampbravoPageDefs.LinkDestinations):
                print ('skipping %s because definition does not exist' % bkPage)
                continue
            # setting up the destination from the definition
            params = CampbravoPageDefs.LinkDestinations[bkPage]
            (bkAge, spawnPoint, spTitle, linkRule,) = params
            alink = 1
            if (type(bkAge) != type(None) and forceOwned):
                print ('ownership check for %s book' % bkAge)
                vault = ptVault()
                ainfo = ptAgeInfoStruct()
                ainfo.setAgeFilename(bkAge)
                alink = vault.getOwnedAgeLink(ainfo)
            if alink:
                print ('showing page for %s' % bkAge)
                if (type(bkAge) != type(None)):
                    t = (PageCount, bkAge, spawnPoint, spTitle, linkRule)
                    bkLinks.append(t)
                    PageDef = PageDef + CampbravoPageDefs.BookPages[bkPage] % (PageCount) + '<pb>'
                else:
                    PageDef = PageDef + CampbravoPageDefs.BookPages[bkPage] + '<pb>'
                PageCount = PageCount + 1
            else:
                print ('No %s book on your shelf so we are not showing the link' % bkAge)
        if (PageCount == xLinkingBookDefs.kFirstLinkPanelID):
            print 'no pages created'
            return
        print ('linkingpages created: %d' % (len(bkLinks)))
        PageDef = PageDef[:-4]
        ourBook = ptBook(PageDef, self.key)
        ourBook.setSize(1.0, 1.0)
        ourBook.setGUI('BkBook')
        ourBook.show(0) # 0 = closed book, 1 = open book



    def IlinkToAge(self, ageName, spawnPoint, theTitle = None, linkRule = PtLinkingRules.kBasicLink):
        print ('%s: ILinkToAge: Link request for age %s' % (self.__class__.__name__, ageName))
        als = ptAgeLinkStruct()
        ainfo = ptAgeInfoStruct()
        ainfo.setAgeFilename(ageName)
        ainfo.setAgeInstanceName(self.IConvertAgeInstanceName(ageName))
        als.setAgeInfo(ainfo)
        if (type(theTitle) != type(None)):
            spTitle = theTitle
            ##################################################
            # Spawnpoint title is defined. Continue linking. #
            ##################################################
        else:
            if ((linkRule == PtLinkingRules.kOriginalBook) or PtIsSinglePlayerMode()):
                ##############################################################################
                # Linkingrule kOriginalBook writes spawnpoint and title to the agelink node, #
                # so we must make absolutely sure that a proper title is given!              #
                # In singleplayer mode all linkingrules behave like kOriginalBook, no matter #
                # which linkingrule is set in the definition.                                #
                ##############################################################################
                if (spawnPoint == 'LinkInPointDefault'):
                    spTitle = 'Default'
                    #################################################################################
                    # We did not define a spawnpoint title, but since the spawnpoint is the default #
                    # it is safe to continue and write it to the agelink node with default title.   #
                    #################################################################################
                else:
                    print 'Empty spawnpoint title not allowed, check your linking page definitions!'
                    return
            else:
                print 'Empty spawnpoint title allowed, continue linking'
                spTitle = ''
        als.setLinkingRules(linkRule)
        spPoint = ptSpawnPointInfo(spTitle, spawnPoint)
        als.setSpawnPoint(spPoint)
        linkMgr = ptNetLinkingMgr()
        linkMgr.linkToAge(als)
        print ('Linking to age %s, spawnpoint %s with title %s, using linkingrule %d' % (ageName, spawnPoint, spTitle, linkRule))



    def IConvertAgeInstanceName(self, ageName):
    #########################################################################################################################
    # Optional: You can add a friendly name to this list for the age you link to. This is the name that shows up in the KI. #
    # Ahra Pahts and Relto are used here only as examples.                                                                  #
    # Some Cyan age names are converted to friendly names in the KI but we cannot expect the KI to do that for user ages.   #
    # Beware: Age instance names are written to the vault if the kOriginalBook rule is used. That will happen whether you   #
    # set a name here or not. And it would happen regardless of this function.                                              #
    # By default the age instance name is the same as the age name.                                                         #
    # btw, if you plan to link to Cyan ages you should set the correct age instance name here. Correct? You figure it out!  #
    #########################################################################################################################
        if (ageName == 'Personal'):
            return 'Relto'
        if (ageName == 'Pahts'):
            return 'Ahra Pahts'
        return ageName
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Dynamic Book Template

Postby D'Lanor » Wed Jan 30, 2008 8:43 am

Is that the full file? It is missing the standard glue stuff appended at the end. I should have mentioned that I had left that out. :oops:
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 9:06 am

So I just need to "Paste" the "Glue"........?


MWAHAHAHAHAHAHAHAHAHAHAH...........

Okay, I'm loosing it now.........hehehe.......

I took a break from this and here, went over to the MOUL forums to relax......

Duh! Big mistake. I forgot, I go to the UO forums to relax......MOUL Forums is for Hostile Battles due to some of the people there that are quite..........caustic is about a polite term that I'll use. :roll:

Okay! :rubs hands together: Paste the Glue then it is!
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 9:16 am

Okay! Still nothing happening when I click on the book, BUT! I got a different error in the Log now!

I clicked on the book twice:

(01/30 11:13:44) __init__CampbravoBookGUI v.1
(01/30 11:13:48) CampbravoBookGUI: OnFirstUpdate called
(01/30 11:13:55) CampbravoBookGUI: OnNotify called
(01/30 11:13:55) Someone clicked an object
(01/30 11:13:55) It was you
(01/30 11:13:55) Traceback (most recent call last):
(01/30 11:13:55) File ".\python\CampbravoBookGUI.py", line 42, in OnNotify
(01/30 11:13:55) for i in range(0, len(ageBooks)):
(01/30 11:13:55) TypeError: len() of unsized object
(01/30 11:13:55) CampbravoBookGUI: OnNotify called
(01/30 11:13:58) CampbravoBookGUI: OnNotify called
(01/30 11:13:58) Someone clicked an object
(01/30 11:13:58) It was you
(01/30 11:13:58) Traceback (most recent call last):
(01/30 11:13:58) File ".\python\CampbravoBookGUI.py", line 42, in OnNotify
(01/30 11:13:58) for i in range(0, len(ageBooks)):
(01/30 11:13:58) TypeError: len() of unsized object
(01/30 11:13:58) CampbravoBookGUI: OnNotify called
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Dynamic Book Template

Postby D'Lanor » Wed Jan 30, 2008 9:22 am

Now we are getting somewhere. :) ageBooks is set to None while it should contain the name of your clickable object.
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Dynamic Book Template

Postby andylegate » Wed Jan 30, 2008 9:26 am

I was JUST looking at that. Your template, and my file.

Let me ask you this (please don't roll eyes, I know, I'm a noob, but I don't know where to go to learn Python Scripting better, so be patient with me):

Code: Select all
ageBooks = ('Journal', 'OtherJournal')
    bookPages = (['PradJournal', 'CleftDrop'], ['FontTest'])


That's your template above.
What is an "ageBooks" and what is "bookPages"

From what you just said, ageBooks is the object that I'm clicking on, okay, I can put my welcomebk in there, and remove OtherJournal. NP.

But what do I put for bookPages?

EDIT: okay, hey, looking at it again........
PradJournal and FontTest are in the PageDefs file......
They are also in the external Journals.py file..........

Hmmmmm......
So, do I put welcomebk (the name of the journal and object in my age) for both ageBooks and bookPages? It seems like it.
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron