Page 1 of 1

Each-Step Goofiness

Posted: Wed Oct 31, 2012 12:03 am
by Gizmog
I'm just now starting on what I hope to be my entry to HOTOHR. I'm also experiencing some goofiness with each-step scripts. I've worked around the problem for now, but I might need to know more about this later.

My game has a compass feature, that checks which direction the hero is facing and sets a text slice to display the appropriate information. I used a simple Each-Step script to accomplish that, but noticed that even though the script worked, everytime I started the game I got an invalid slice error.

Eventually, I determined this was because the Each-Step script was somehow occuring BEFORE my new game script which loads the slices. I used the following script to test which happened first and everytime I was immediately returned to the title screen.

Code: Select all

#I run on-each step and end the game if tag 4 is off!
plotscript,GoofySteps,begin
if (checktag (4)==off)
then (gameover)
end

#I run every new-game and set tag 4 on!
plotscript,GoofyNew,begin
settag (4,on)
end
Is that working as intended? I got around this problem by using the seteachstepscript command in my new game script, but I almost didn't try because the dictionary entry makes it sound like you can't use the @scriptname trick that the other map script commands use, and I couldn't find the old style command to define a plotscript.

In summary:

1) It seems like Each-Step scripts trigger before NewGame scripts. Is that expected?

2) The dictionary entry for seteachstepscript discouragingly implies it doesn't work like other similar commands, even though it does.

3) Is there ever a reason to use the old way of defining scripts?

Sorry if this is the wrong place to ask about this, or if this has been discussed before.

Re: Each-Step Goofiness

Posted: Wed Oct 31, 2012 12:41 am
by Bob the Hamster
Gizmog wrote: 1) It seems like Each-Step scripts trigger before NewGame scripts. Is that expected?
I think this is actually according to plan (although I won't claim it was a good plan)

I believe what happens is:

* the new-game/load-game script triggers
* the hero is placed on the map and their first each-step is triggered
* the script interpreter actually starts
* the each-step finishes
* the new-game/load-game script actually starts

TMC might have something to say about this, he knows the script interpreter much better than I do.

For now, I think the simplest safest workaround is to check if the slice handle is valid before you use it in the each-step script. That means the first call to the each-step will do nothing. You can manually call the each-step at the end of the new-game/load-game if you want to make sure the compass updates right away.
Gizmog wrote: 2) The dictionary entry for seteachstepscript discouragingly implies it doesn't work like other similar commands, even though it does.
Do you mean the part that says "The effect goes away if you change maps or fight a battle."?
Gizmog wrote: 3) Is there ever a reason to use the old way of defining scripts?
Never. "define script" is only still supported for backcompat, there are zero good reasons to use old-style scripts for new games.
Gizmog wrote:Sorry if this is the wrong place to ask about this, or if this has been discussed before.
This is an excellent place to ask :)

Re: Each-Step Goofiness

Posted: Wed Oct 31, 2012 1:50 am
by Gizmog
[quote="Bob the Hamster"]
Do you mean the part that says "The effect goes away if you change maps or fight a battle."?[quote]

No, I mean the part that says "The argument is the script's ID number, NOT the script's name." as opposed to "The argument is the script's name preceded by an @ sign. You can also use the ID number for old-style scripts."

I agree with you on the safe way to double check, that's what I had implemented before I got seteachstep to work.

Posted: Wed Oct 31, 2012 3:08 am
by charbile
Could you explain the compass feature? Curious what use it would be. Wouldn't it always point up?

Would suggest simply running a while loop that checks if the hero has moved rather than using the each step. Like a game_controller object, but ohr gangnam style.

Posted: Wed Oct 31, 2012 3:54 am
by Bob the Hamster
Oh! I see! Thanks for noticing that. I fixed the "set each step script" docs

Posted: Wed Oct 31, 2012 7:37 am
by TMC
I didn't know that the each-step script happens before the new-game script. That's pretty awful. I haven't made any changes to trigger order for compatibility, though I will consider adding a general pref bitset to switch to a saner scheme. To add to the confusion, zone trigger options will add per-zone entering, leaving, and each-step script triggers, and it would be bad if those are too inconsistent with regular each-step scripts.
charbile wrote:Would suggest simply running a while loop that checks if the hero has moved rather than using the each step. Like a game_controller object, but ohr gangnam style.
Yes, I wouldn't use an each-step script because:
-nothing happens if the hero changes direction by trying to move into an obstacle but doesn't take a step
-there's a delay because the eachstep script isn't called until after the move is finished

Posted: Wed Oct 31, 2012 1:04 pm
by Gizmog
I had actually wanted a little delay because it only needs to check once a move has been finished, but not triggering when the hero changes direction is problematic. I'll work it into the while loop, thanks for the advice.