Author Topic: doit() and changeState() in room script  (Read 6599 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

doit() and changeState() in room script
« on: January 06, 2013, 07:47:25 PM »
I can't seem to get these to both work together in the same room script.  When I attempt to have both methods in my room, it seems to break the 'state progression' counter.  The doit() still operates normally, but the 'state' variable used in the changeMethod never gets incremented.


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Collector

Re: doit() and changeState() in room script
« Reply #1 on: January 06, 2013, 08:47:46 PM »
Just a shot in the dark, but can you increment it in the doit()? If so, perhaps you could do it indirectly by having the changeState() populate a temporary variable that the doit() could read to increment the state variable.
KQII Remake Pic

Offline Cloudee1

Re: doit() and changeState() in room script
« Reply #2 on: January 06, 2013, 10:44:27 PM »
You may have to post some code for this one Gumby. I don't recall ever having trouble with having a doit and a changestate in the same room stepping on each other.

In fact I usually have several changestates operating at the same time in conjunction with a couple of things that the doit method is watching for.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: doit() and changeState() in room script
« Reply #3 on: January 07, 2013, 09:54:59 AM »
I'm wondering if this is a result of the timer bug not being fixed in the game template that I'm using.  I'll check this later today & see if the bug fix is in there or not.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Doan Sephim

Re: doit() and changeState() in room script
« Reply #4 on: January 07, 2013, 01:51:30 PM »
Shot in the dark - if your doit() method is the trigger of the changeState() it will do so every cycle unless you have something that changes.

Code: [Select]
(method(doit)
 (super:doit)
 (if(& (send gEgo:onControl()) ctlBROWN)
  (RoomScript:changeState(2))
 )
)
This code for instance seems like it would trigger the changeState when Ego is on ctlBROWN, but actually the changeState won't progress until he is on Brown and then steps off.

To avoid this, I usually just add a variable
Code: [Select]
(method(doit)
 (super:doit)
 (if(& (send gEgo:onControl()) ctlBROWN)
  (if(not(brownTrigger))
   (RoomScript:changeState(2))
   = brownTrigger 1
  )
 )
)

Offline gumby

Re: doit() and changeState() in room script
« Reply #5 on: January 07, 2013, 06:20:11 PM »
Here's what I have.  If I remove the doit() method, I can reach state 6.  Otherwise, I never get to state 6.  I've checked and the timer bug is already fixed.  You can try this code in a new template game:

Code: [Select]
(instance RoomScript of Script
    (properties)
    (method (doit))    // yeah, I know it's empty.  Remove this & changeState will work properly
  
    (method (changeState mainState)
             = state mainState
            (switch(state)
               (case 0)
               (case 5
                = seconds 3
               )
               (case 6
             Print("State 6!")
               )
             )
     )

    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))

        /*****************************************
         * Handle the possible said phrases here *
         *****************************************/
        (if(Said('look'))
            (RoomScript:changeState(5))
        )
    )
)

So to test, run the game and type 'look'.  After 3 seconds you should get the 'State 6!' message pop up, IF you've removed the doit().  Otherwise the print statement never displays.

EDIT:  Nevermind, I found the issue!  I needed this:

Code: [Select]
   (method (doit)  
         (super:doit)   // this is somewhat critical!
    )  

« Last Edit: January 07, 2013, 06:26:23 PM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: doit() and changeState() in room script
« Reply #6 on: January 08, 2013, 05:28:42 PM »
I was just about to point that out before I noticed your edit. The super doit...

Thought your doit method looked a little sparse  :)
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.046 seconds with 19 queries.