Dynamic Book Template (version 2.1)

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

Re: Dynamic Book Template (version 2.1)

Postby D'Lanor » Sun Mar 09, 2008 10:54 am

Yes, but Uru doesn't find it. So where is the file? Is it in your Python folder? In the Pahts.pak or in a separate pak file? Both should work as long as the file inside the pak has the correct name.
"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 (version 2.1)

Postby Grogyan » Sun Mar 09, 2008 9:45 pm

I found one small typo, the file was named s119BookGui.py, but it was being referenced by AlcScript and logic properties as s119BookGUI

Still no luck
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Dynamic Book Template (version 2.1)

Postby andylegate » Mon Mar 10, 2008 3:24 am

I still think it would be best at this point for you to copy and past your two python files here and let us look at them. We don't need the journal contents, as that one won't cause the problem. But if we could look at your other two files, maybe we can spot something you might be missing. Many eyes are better than 2, yes?
"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 (version 2.1)

Postby Grogyan » Mon Mar 10, 2008 10:10 am

s119PageDefs.py
Code: Select all
# For each occurance of *YourAge* and *YourTexture* you have to replace this with
# the actual name of your age and your textures.

from Plasma import *
from PlasmaNetConstants import *
# Due to their length journal texts are usually stored in external Python files.
# The line below imports them. Remove this line if you do not use external journals.
from s119Journals import *

# General layout elements that can be used in BookPages:
plyrName = PtGetLocalPlayer().getPlayerName() # Retrieves local player name in case you want to fake a "personal" note
PageStart = '<pb>'
ImgStart = '<img src="'
TransImgStart = '<img opacity=0.7 src="'
ImgEnd = '" align=center link=%d blend=alpha>'
ImgEndNoLink = '" align=center blend=alpha>'
AlignCenter = '<p align=center>'
AlignLeft = '<p align=left>'
AlignRight = '<p align=right>'

###############################################################################
# AgeBooks Dictionary Section:                                                #
# 1 =    same names as the clickable book objects!                            #                     
# 2 =    book cover and margin                                                #
# 3 =    main font                                                            #
# 4 =    start book open or closed. 0 closed book, 1 open book                #
# 5 =    force owned setting. 0 off, 1 on                                     #
#                                                                             #
# Notes: - The cover can have the same texture as the book object itself.     #
#        - You can set the book cover to an empty string if startOpen is 1.   #
#        - The main font can be changed later in the BookPages definition.    #
#          If you don't need a main font (because you are changing it later), #
#          you can set an empty string.                                       #
#        - force owned: If 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. If you need this restriction set force owned to 1.  #
###############################################################################

AgeBooks = {'s119JournalBook': ('<cover src="119journal"><margin right=32 left=32>', '<font size=12 face=Arial color=000000>', 0, 0)}

###############################################################################################
# BookPages Dictionary Section:                                                               #
# 1 =    Same names as used under link destinations!                                          #
# 2 =    The page layout: for linking books insert the name of your linking panel image here. #
#        This can be a seperate texture in your age prp file not used by a Blender object     #
#        (not sure if Blender handles that: use PRP Explorer).                                #
#        Once you get the hang of this you can mix and match layouts into your pages.         #
#                                                                                             #
# Notes: - AlignCenter is used to center text, for example to place below a linking panel.    #
###############################################################################################

BookPages = {'s119Journals': (PageStart + (DefPradJournal % plyrName))}

###############################################################################
# LinkDestinations Dictionary Section:                                        #
# 1 =    any name (this is used to call the definitions)                      #
# 2 =    age name                                                             #
# 3 =    spawnpoint                                                           #
# 4 =    spawnpoint title                                                     #
# 5 =    linkingrule                                                          #
#                                                                             #
# Notes: - Variables for journals are dummies and must be set to None.        #
#        - Spawnpoint title None is only allowed for LinkInPointDefault       #
#          (although it would be better to set it to 'Default' in that case). #
#        - CleftDrop in this example will deliberately fail (see above).      #
###############################################################################

LinkDestinations = {'s119Journals': (None, None, None, None)}


s119BookGUI.py
Code: Select all
###########################################
#                                         #
#  Dynamic Book Template v2.1 by D'Lanor  #
#                                         #
###########################################

# For each occurance of *YourAge* you have to replace this with the actual name of your age.

from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
from PlasmaNetConstants import *
import xLinkingBookDefs
import s119PageDefs
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')

### DO NOT CHANGE THESE ###
ourBook = None
bkLinks = []

### CHANGE THE GLOBAL CONSTANTS BELOW TO FIT YOUR AGE ######################################
#                                                                                          #
# ageBooks:   These are your clickable objects. They must be defined in *YourAge*PageDefs  #
#             in the AgeBooks Dictionary Section by the same name(s).                      #
# bookPages:  Names in bookPages must be defined in the *YourAge*PageDefs file under       #
#             BookPages. An ageBook can have multiple bookPages as long as they are        #
#             enclosed together between the same square brackets.                          #
#             Please keep the nesting structure [square brackets] intact!                  #
#                                                                                          #
# If there are multiple books in an age the code will find the right one automagically.    #
# You can add as many books as you like. Just define them in the global variables ageBooks #
# and bookPages. The order is important here. The first book will be matched to the first  #
# page list, the second book to the second page list etc.                                  #
############################################################################################

ageBooks = ['s119JournalBook']
bookPages = ['s119Journals']

class s119BookGUI(ptModifier,):

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



    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 on object %s' % ObjectMsg.value)
            if (PtWasLocallyNotified(self.key)):
                print 'It was you'
                for a, b in zip(ageBooks, bookPages):
                    print ('Try book %s with page(s) %s' % (a, b))
                    if (ObjectMsg.value == a):
                        print 'Match found! start opening...'
                        self.IOpenBook(a, b)
                        break

        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, ageBook, bkPages = None):
        global ourBook
        global bkLinks
        print ('%s: IOpenBook: Page request for %s' % (self.__class__.__name__, bkPages))
        if (type(bkPages) == type(None)):
            print 'ERROR: no pages defined'
            return
        if (not ageBook in s119PageDefs.AgeBooks):
            print ('ERROR: Definition %s does not exist' % ageBook)
            return
        bkParams = s119PageDefs.AgeBooks[ageBook]
        (bkCover, bkFont, startOpen, forceOwned,) = bkParams
        PageDef = bkCover + bkFont
        if (not startOpen):
            if (not self.IsThereACover(PageDef)):
                print 'Warning: Missing cover, forcing book open'
                startOpen = 1
        PageCount = xLinkingBookDefs.kFirstLinkPanelID
        bkLinks = []
        for bkPage in bkPages:
            if (not bkPage in s119PageDefs.LinkDestinations):
                print ('Skipping %s because definition does not exist' % bkPage)
                continue
            pgParams = s119PageDefs.LinkDestinations[bkPage]
            (bkAge, spawnPoint, spTitle, linkRule,) = pgParams
            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 + s119PageDefs.BookPages[bkPage] % (PageCount) + '<pb>'
                else:
                    PageDef = PageDef + s119PageDefs.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 ('Linking pages created: %d' % (len(bkLinks)))
        PageDef = PageDef[:-4]
        ourBook = ptBook(PageDef, self.key)
        ourBook.setSize(1.0, 1.0)
        ourBook.setGUI('BkBook')
        ourBook.show(startOpen)



    def IsThereACover(self, bookHtml):
        idx = bookHtml.find('<cover')
        if (idx >= 0):
            return 1
        return 0



    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
        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



glue_cl = None
glue_inst = None
glue_params = None
glue_paramKeys = None
try:
    x = glue_verbose
except NameError:
    glue_verbose = 0

def glue_getClass():
    global glue_cl
    if (glue_cl == None):
        try:
            cl = eval(glue_name)
            if issubclass(cl, ptModifier):
                glue_cl = cl
            elif glue_verbose:
                print ('Class %s is not derived from modifier' % cl.__name__)
        except NameError:
            if glue_verbose:
                try:
                    print ('Could not find class %s' % glue_name)
                except NameError:
                    print 'Filename/classname not set!'
    return glue_cl



def glue_getInst():
    global glue_inst
    if (type(glue_inst) == type(None)):
        cl = glue_getClass()
        if (cl != None):
            glue_inst = cl()
    return glue_inst



def glue_delInst():
    global glue_inst
    global glue_cl
    global glue_paramKeys
    global glue_params
    if (type(glue_inst) != type(None)):
        del glue_inst
    glue_cl = None
    glue_params = None
    glue_paramKeys = None



def glue_getVersion():
    inst = glue_getInst()
    ver = inst.version
    glue_delInst()
    return ver



def glue_findAndAddAttribs(obj, glue_params):
    if isinstance(obj, ptAttribute):
        if glue_params.has_key(obj.id):
            if glue_verbose:
                print 'WARNING: Duplicate attribute ids!'
                print ('%s has id %d which is already defined in %s' % (obj.name,
                 obj.id,
                 glue_params[obj.id].name))
        else:
            glue_params[obj.id] = obj
    elif (type(obj) == type([])):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type({})):
        for o in obj.values():
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type(())):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)




def glue_getParamDict():
    global glue_paramKeys
    global glue_params
    if (type(glue_params) == type(None)):
        glue_params = {}
        gd = globals()
        for obj in gd.values():
            glue_findAndAddAttribs(obj, glue_params)

        glue_paramKeys = glue_params.keys()
        glue_paramKeys.sort()
        glue_paramKeys.reverse()
    return glue_params



def glue_getClassName():
    cl = glue_getClass()
    if (cl != None):
        return cl.__name__
    if glue_verbose:
        print ('Class not found in %s.py' % glue_name)
    return None



def glue_getBlockID():
    inst = glue_getInst()
    if (inst != None):
        return inst.id
    if glue_verbose:
        print ('Instance could not be created in %s.py' % glue_name)
    return None



def glue_getNumParams():
    pd = glue_getParamDict()
    if (pd != None):
        return len(pd)
    if glue_verbose:
        print ('No attributes found in %s.py' % glue_name)
    return 0



def glue_getParam(number):
    pd = glue_getParamDict()
    if (pd != None):
        if (type(glue_paramKeys) == type([])):
            if ((number >= 0) and (number < len(glue_paramKeys))):
                return pd[glue_paramKeys[number]].getdef()
            else:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getdef()
            elif glue_verbose:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



def glue_setParam(id, value):
    pd = glue_getParamDict()
    if (pd != None):
        if pd.has_key(id):
            try:
                pd[id].__setvalue__(value)
            except AttributeError:
                if isinstance(pd[id], ptAttributeList):
                    try:
                        if (type(pd[id].value) != type([])):
                            pd[id].value = []
                    except AttributeError:
                        pd[id].value = []
                    pd[id].value.append(value)
                else:
                    pd[id].value = value
        elif glue_verbose:
            print "setParam: can't find id=",
            print id
    else:
        print 'setParma: Something terribly has gone wrong. Head for the cover.'



def glue_isNamedAttribute(id):
    pd = glue_getParamDict()
    if (pd != None):
        try:
            if isinstance(pd[id], ptAttribNamedActivator):
                return 1
            if isinstance(pd[id], ptAttribNamedResponder):
                return 2
        except KeyError:
            if glue_verbose:
                print ('Could not find id=%d attribute' % id)
    return 0



def glue_isMultiModifier():
    inst = glue_getInst()
    if isinstance(inst, ptMultiModifier):
        return 1
    return 0



def glue_getVisInfo(number):
    pd = glue_getParamDict()
    if (pd != None):
        if (type(glue_paramKeys) == type([])):
            if ((number >= 0) and (number < len(glue_paramKeys))):
                return pd[glue_paramKeys[number]].getVisInfo()
            else:
                print ('glue_getVisInfo: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getVisInfo()
            elif glue_verbose:
                print ('glue_getVisInfo: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



My eyes have gone square, I hope you can see the problem, cause I can't.

Thanks
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Dynamic Book Template (version 2.1)

Postby D'Lanor » Mon Mar 10, 2008 11:19 am

I don't see any major errors. Perhaps the naming of the cover texture which does not point to a texture file. But that would not keep the book from opening.

I don't think your current problem is in the python files. It didn't even get that far. Or maybe it did after you corrected the typo? Does the logfile still say it cannot be found?

As a sidenote, I see that you used the plyName variable. I take it you aware that there should be a %s inside your journal text for that to work?

Edit: Another thing, reading back I see that your region has a ConvexHullPolytype collision. Regions should not have collision. Although I think the plugin will ignore that anyway.
Last edited by D'Lanor on Mon Mar 10, 2008 11:36 am, edited 1 time in total.
"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 (version 2.1)

Postby boblishman » Mon Mar 10, 2008 11:34 am

is that the WHOLE of your s119PageDefs.py file... if so, the glue is missing ... :(
when it comes to Age creation ... "DOH" seems to be my middle name...
User avatar
boblishman
 
Posts: 882
Joined: Fri Oct 05, 2007 4:47 pm
Location: Spain

Re: Dynamic Book Template (version 2.1)

Postby D'Lanor » Mon Mar 10, 2008 11:37 am

PageDefs doesn't need the glue section. Only BookGUI does.
"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 (version 2.1)

Postby andylegate » Mon Mar 10, 2008 12:18 pm

Okay, I see something here, and looks like a problem, it's this line here in the PageDefs:

Code: Select all
BookPages = {'s119Journals': (PageStart + (DefPradJournal % plyrName))}


Shouldn't that read:

Code: Select all
BookPages = {'s119Journals': (PageStart + (Def119Journals % plyrName))}


Not sure what he has in his Journal contents, since the one included with the RAD upload is simply a copy of the book template (meaning Font Test and DefPradJournal) are there.

Also, in the original book template, you have bookpages nested in double brackets. But then there were multiple books. Does he need to keep the nesting even though it's only one book?

Code: Select all
ageBooks = ['s119JournalBook']
bookPages = ['s119Journals']


Or should it be:

Code: Select all
ageBooks = ['s119JournalBook']
bookPages = [['s119Journals']]


Other than that I don't see any problems with these python files. Now the one that was downloaded for the RAD, yes, those won't work, as there are problems with those.

Let me ask again as I'm being dense today. You move to the book, and now you are getting the click hot spot when you move the mouse over the journal, meaning you can click on it, but when you click, nothing happens, right?
"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 (version 2.1)

Postby Grogyan » Mon Mar 10, 2008 1:07 pm

Thats ok Andy,
what you just described is whats happening, the journal book model object center is within the region.

I have been told that for any region, if no bounds are set then the default is "ConvexHullPolytope", the engine needs to know that the avatar can collide with it, then knows its a region and lets the avatar to pass through it unimpeded and trigger an event flag.

The DefPrad line is the line that is called in the s119Journals.py file which its contents are identical to what is included in the zip file on the first post of this thread, and is essentially the journal text itself.

When I get home, I can put the extension back in for the cover texture and see he that works.
Better to have loved and lost than never to have loved at all
User avatar
Grogyan
 
Posts: 1203
Joined: Thu Oct 11, 2007 1:27 am

Re: Dynamic Book Template (version 2.1)

Postby D'Lanor » Mon Mar 10, 2008 1:32 pm

Since the s119BookGui.py file is not found I still would like to know is how you compiled the Python pak file. What is its name? What is the filedate? Is the main Pahts.pak file newer? (yes, that is important) And what are the names of the files inside the pak? Are any of those files inside other pak files as well? Could your pak file be corrupt?
"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

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron