Page Swapping

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

Page Swapping

Postby D'Lanor » Mon Jan 28, 2008 11:49 am

Page Swapping

This example shows how to conditionally load different versions of your age from different pages. This can be useful for day-night toggles, dry-rainy ages or seasonal ages. The method works more or less like a conditional object, except that it comprises the major part of an age.

In order to remain true to the Minkata scenario a clickable object is used as trigger for the page swap. There is also an optional Minkata type fake link effect.

You will have to edit several files outside of Blender. At least I don't think the current plugin supports customizing the fni and age files (but someone please correct me if I am wrong). Programs you can use for this: UruFun or PlasmaShop.


Step 1: Blender
In Blender you have to create 3 pages. The two pages that you want to toggle and a third page that contains shared objects.

The shared page must contain your link-in point(s) and the clickable trigger object including its clickable region. You may also have to add your horizontal collision plane(s) to the shared page if you experience falling, although in my demo age that did not seem to be necessary.

Your age must also have an AgeSDLHook.


Step 2: The age file
Edit the *.age file that PyPRP creates as follows. Add ,1 to the end of the line that contains your conditional pages. This tells the game not to load those pages by default when the age loads. So if for example you have the pages PageZero and PageOne which you want to toggle you change this:

Code: Select all
Page=PageZero,0
Page=PageOne,1

Into this:

Code: Select all
Page=PageZero,0,1
Page=PageOne,1,1

The shared page must remain unaltered.


Step 3: The SDL file
Create a *.sdl file for your age:

Code: Select all
#==============================================================
# READ:   When modifying an SDL record, do *not* modify the
#   existing record. You must copy and paste a new version
#   below the current one and make your changes there.
#==============================================================


#
# State Description Language for YourAge

STATEDESC YourAge
{
   VERSION 1

   VAR BOOL    SwapPage[1]    DEFAULT=0
}


Adapt "YourAge" to the name of your age. If you want you can also rename the variable "SwapPage".


Step 4: The Python code
The code is designed as a template. You only have to adjust the global constants and variables at the top of the file.

  1. AgeSDLHook
    This Python file must have the same name as your age. It is automatically called upon link-in. In the source zipfile it is Swap.py. Variables to adjust are:

    SDLName = 'SwapPage' #The name of your SDL variable (see step 3)
    sPages = ('PageZero', 'PageOne') #The names of the two toggle pages
    sFog = ([0, 1000, 1], [0, 1000, 1]) #The fog density settings of the two toggle pages (in this case similar). Overrides the fni file settings.
    sColors = ([0.5, 0.5, 0.5], [0.0, 0.0, 0.0]) #The fogcolors of the two toggle pages. Overrides the fni file settings.

  2. PythonFileMod
    This is the Python file that your clickable object calls. In the source zipfile it is SwapButton.py. Variables to adjust are:

    clickObj = 'Button' #The name of your clickable object
    SDLName = 'SwapPage' #The name of your SDL variable (see step 3)
    sPages = ('PageZero', 'PageOne') #The names of the two toggle pages
    sFog = ([0, 1000, 1], [0, 1000, 1]) #The fog density settings of the two toggle pages (in this case similar). Overrides the fni file settings.
    sColors = ([0.5, 0.5, 0.5], [0.0, 0.0, 0.0]) #The fogcolors of the two toggle pages. Overrides the fni file settings.
    linkEffects = 1 #enable/disable effects (0=disabled, 1=enabled)
    #tweak the link effects below if needed
    kButtonSeconds = 0.1
    kFadeOutSeconds = 1.5
    kAudioSeconds = 3.0
    kIdleSeconds = 6.0
    kFadeInSeconds = 1.5

See attachment (swap_source.zip) for the full Python code.

swap_demo.zip
(30.61 KiB) Downloaded 229 times


swap_source.zip
(5.26 KiB) Downloaded 235 times
"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: Page Swapping

Postby Chacal » Mon Jan 28, 2008 2:18 pm

Awesome. I was planning to someday have a look at programming, this seems to be the way to get acquainted.
Put it in the wiki!
Chacal


"The weak can never forgive. Forgiveness is an attribute of the strong."
-- Mahatma Gandhi
User avatar
Chacal
 
Posts: 2508
Joined: Tue Nov 06, 2007 2:45 pm
Location: Quebec, Canada

Re: Page Swapping

Postby Robert The Rebuilder » Tue Mar 11, 2008 10:01 am

D'Lanor:

You can avoid editing the .age file by simply adding the following line under each conditional page's entry in the "Book" AlcScript:
Code: Select all
        hide: true


When exporting your age, the plugin will add the ',1' to the end of each page's entry in the .age file.
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Page Swapping

Postby D'Lanor » Tue Mar 11, 2008 11:21 am

Cool. Thanks!

I was actually still working with 0.5 when I made this.

I am glad this was bumped up because I have simplified it since I posted. Everything in the AgeSDLHook can be moved to the regular PythonFileMod, since both are initialized when the age loads.
"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: Page Swapping

Postby Robert The Rebuilder » Sat Mar 15, 2008 8:36 pm

I finally managed to get this working with Prin Pahts. To do this, I placed the Prin Pahts floor collider and spawn points in a non-hidden page, and I made Prin Pahts a hidden page. In the script, I page in Prin Pahts when I link down to it, and when I link back up to the city, I page it out. The time it takes to load in Prin is about the same time as the forced blackout period I put in - about 2 seconds. So this has some great possibilities with the city at large and at reducing the overall load time!

One note: for the longest time I was having a problem with paging in Prin Pahts, but having it appear 1000 feet above me. I eventually figured out that it was loading in an earlier version of Prin Pahts from a test age (which was named "LinkTest01_District_Prin.prp"), which used to be 1000 feet higher. After I deleted that age, it paged in my new version of Prin Pahts. So, it seems that PtPageInNode() does not check to see if the page is of the same age - it seems to ignore the "<AgeName>_District_" when searching for a matching page. Theoretically, you could page in any age's page, for some interesting mash-ups (like Zardoz had chronicled here). Weird, huh?
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Page Swapping

Postby D'Lanor » Sat Mar 15, 2008 11:08 pm

Yes, long ago before we could build our own ages I remember testing this and paging in the Cleft into Relto. :D I guess we better not use it on mainRoom then... ;) This could be a potential risk. We need to make sure that pages loaded this way have a proper agename prefix.

I am glad that you reminded me of this behavior because I was in the process of making Prad, which uses this technique, ready for release without the prefixes.

The global animations btw are made available in a similar way. They are loaded with a Plasma console command into a "PageInHoldList". Perhaps we could use the Python function PtPageInHold(nodeName) for things we want to have globally available but not directly visible. There is no PtPageOutHold though.
"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


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests