Can't Find Source of Problem (Scripting)

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Can't Find Source of Problem (Scripting)

Post by sheamkennedy »

I'm running in to a small problem with my script. I have the codes set up as an each-step script on my map. It checks to see if the characters are standing on a particular zone, then it changes their sprite accordingly. This script in particular checks whether you are standing on a ladder or on the ground, then changes your character to climbing or standing respectively.

The problem I'm having is when my characters mount the ladder their z (height) value appears to change from 0 to 4. There is nowhere in my script where I have the z-value changing to 4. I simply want the hero's z to remain the same when they mount the ladder.

I have done a lot of searching for the cause of this and still cannot figure it out. If anyone can find the problem, or suggest some troubleshooting technique that would be great, thanks.

The code is:

Code: Select all

### Zone 1 - Changes party hero sprites to default
  If (read zone (1, x, y)) then(
	set hero speed(me, 4)
	set hero z (0, 0)
	
    If (hero by slot (0) == hero:Taras) then(
      set hero picture (0, 71)
    ) else if (hero by slot (0) == hero:Antonina) then(
      set hero picture (0, 18)
    )
    embiggen now
  ) 

  If (read zone (1, a, b)) then(
	set hero speed(me, 4)
	set hero z (1, 0)
	
    If (hero by slot (1) == hero:Taras) then(
      set hero picture (1, 71)
    ) else if (hero by slot (1) == hero:Antonina) then(
      set hero picture (1, 18)
    )
    embiggen now
  )

  ### Zone 2 - Changes sprites to ladder  
  If (read zone (2, x, y)) then(
    set hero speed(me, 4)
    set hero z (0, 0)
    
    If (hero by slot (0) == hero:Taras) then(
      set hero picture (0, 84)
    ) else if (hero by slot (0) == hero:Antonina) then(
      set hero picture (0, 85)
    )
    embiggen now
    
  ) 

  If (read zone (2, a, b)) then(
    set hero speed(me, 4)
    set hero z (1, 0)
    
    If (hero by slot (1) == hero:Taras) then(
      set hero picture (1, 84)
    ) else if (hero by slot (1) == hero:Antonina) then(
      set hero picture (1, 85)
    )
    embiggen now
  )
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hmmm... Interesting.

I think the first thing to figure out is if the hero z is really changing, or if something is just creating the illusion that it is changing. (like foot offset changing, or a hero walkabout slice positioning problem)

Try running a script like this

Code: Select all

script, z checker repeat, begin
  show value(hero z(0))
  # Repeat this script again in 1 tick without blocking other scripts
  set timer(0, 0, 1, @z checker repeat)
end
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Bob the Hamster wrote:Hmmm... Interesting.

I think the first thing to figure out is if the hero z is really changing, or if something is just creating the illusion that it is changing. (like foot offset changing, or a hero walkabout slice positioning problem)

Try running a script like this

Code: Select all

script, z checker repeat, begin
  show value(hero z(0))
  # Repeat this script again in 1 tick without blocking other scripts
  set timer(0, 0, 1, @z checker repeat)
end
Thank you, I found the problem. Somehow I had accidentally placed a zone #12 on my ladder which causes elevation to change to 5. Your troubleshooting code helped me find out which zone it was since I was able to search my script for z being 5.

Your solution has actually lead me to another question. Do timers execute their assigned script simultaneously?

You said the timer repeats without blocking other scripts, so if I run 2 timers that end at the same time, will they execute the 2 assigned scripts at the same time? Or will one have precedence over another?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

sheamkennedy wrote: Thank you, I found the problem. Somehow I had accidentally placed a zone #12 on my ladder which causes elevation to change to 5. Your troubleshooting code helped me find out which zone it was since I was able to search my script for z being 5.
Excellent! Glad to help :)
sheamkennedy wrote:Your solution has actually lead me to another question. Do timers execute their assigned script simultaneously?

You said the timer repeats without blocking other scripts, so if I run 2 timers that end at the same time, will they execute the 2 assigned scripts at the same time? Or will one have precedence over another?
Timer scripts don't run simultaneously, but two or more timer scripts scheduled for the same tick will run in the same tick.

timer scripts are run in the order of their timer id number.

You can think of timer scripts as "fake multitasking". Some games already use them that way (Pepsi Ranger's "Entrepreneur" is the first one that comes to mind.)
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Bob the Hamster wrote:You can think of timer scripts as "fake multitasking". Some games already use them that way (Pepsi Ranger's "Entrepreneur" is the first one that comes to mind.)
That sounds like something I'll definitely be using. I'm surprised that I didn't think to play around with this feature earlier. Thanks.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Bob the Hamster wrote:timer scripts are run in the order of their timer id number.
Timers are triggered in order of their ID numbers, pushing them onto the script stack, and then executed in reverse order.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

I have a further question regarding timers. I have a timer set so it goes on forever, and changes the screen colour. It seems that there's a few times in the game so far where the screen stops changing colour due to another script running. At other times where other scripts are running, the colour seems to continue to change. So what about these certain scripts would "pause" the timer? I would like my timer to always run if possible, during menus, during battles, and during all scripts.

If you need me to supply scripts for reference let me know.

EDIT: The only difference I can see between the scripts that "allow the timer to run at the same time", and the ones that "don't allow the timer to run at the same time" is that the ones that don't are triggered by stepping on an NPC... Not sure if that's the problem, maybe just a coincidence.
Last edited by sheamkennedy on Sun Sep 28, 2014 1:30 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Yes, the order in which the engine triggers scripts affects which gets to run first. I thought that I documented the order somewhere on the wiki, but can't find it.

A newly triggered script always pausing any previous scripts, forming a stack. (You can try gleaning information out of How does plotscripting work?

Sadly I've just realised that timers are triggered in the worst possible place: before everything else. (If it had been placed one line of code earlier it would have been perfect...) If any other script is triggered, like an NPC use script, a script attached to a textbox, etc, and the script contains a wait command, then it will interrupt any timer loops. Sorry about that. So one solution is to not put waits in those scripts. If you do need waits, you could try breaking the script up to use timers, or moving it "underneath" the timer scripts, into a main loop, like this (which is probably easier, but is only an option if you don't already have a looping script running):

Code: Select all

global variable(1, want to start cutscene 1)

plotscript, main loop, begin
  while(true) do(
    # Normally nothing is happening
    if (want to start cutscene 1) then(
      want to start cutscene 1 := false
      # Now this script can contain any waits, and it won't interrupt
      # any timers. Instead, it will be interrupted by everything else
      # that contains waits
      cutscene 1
    )

    wait(1)
  )
end

plotscript, start cutscene 1, begin
  want to start cutscene 1 := true
  # You could set a tag instead; then you wouldn't need this script
end

script, timer loop, begin
  # whatever
  ....
  set timer(1, 1, 0, @timer loop)  # (or whatever the correct arguments may be
end
Also, scripts don't run during battles, so if there's a chance that a battle happens in the middle of your palette fading loop then you need to reset the palette before starting the battle.

Script multitasking will fix this problem. I want to finish implementing script multitasking soon, but it's not the absolute highest priority, and the next stable release is also soon. In fact it should probably be intentionally left out of that release.
Last edited by TMC on Sun Sep 28, 2014 8:44 am, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Alright good to know. Any idea of when script multi tasking would be implemented. It is not a priority of mine to fix this issue anytime too soon, so if that feature is implemented somewhere down the line I could just wait for it.

EDIT: I just played around with what you suggested. I think I like doing it by retriggering the hallucination script within the other scripts which are causing it to pause. I figure it may be best to have a master timer or step counter which determines when the drugs effect has worn off, then tells the coresponding timer to stop. I was thinking of making a tag related system anyways to check what drugs you are currently high off of, that way I can make "combined drug effects" if the scripts see that you are taking two or three at once.
Last edited by sheamkennedy on Sun Sep 28, 2014 6:13 pm, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

sheamkennedy wrote:Alright good to know. Any idea of when script multi tasking would be implemented. It is not a priority of mine to fix this issue anytime too soon, so if that feature is implemented somewhere down the line I could just wait for it.
I don't like to make promises of the sort because I tend to break them, but I really hope to have it done this year. I think it's only a weekend's work. I hate to see people spend hours on convoluted workarounds because of laziness on my part.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

That sounds great. I know nothings set in stone. If it doesn't get implemented til sometime next year I'd be happy just the same.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Pepsi Ranger
Liquid Metal Slime
Posts: 1419
Joined: Thu Nov 22, 2007 6:25 am
Location: South Florida

Post by Pepsi Ranger »

TMC wrote:I don't like to make promises of the sort because I tend to break them, but I really hope to have it done this year. I think it's only a weekend's work. I hate to see people spend hours on convoluted workarounds because of laziness on my part.
Whoa, a weekend's worth of work? Really? Why not just finish it then?
sheamkennedy wrote:Alright good to know. Any idea of when script multi tasking would be implemented. It is not a priority of mine to fix this issue anytime too soon, so if that feature is implemented somewhere down the line I could just wait for it.

That sounds great. I know nothings set in stone. If it doesn't get implemented til sometime next year I'd be happy just the same.
I've been waiting patiently for it since about 2008. So many convoluted workarounds.... Entrepreneur: The Beginning's entire foundation was built on a convoluted workaround.

I've also been waiting patiently for the ability to store battle stats in global variables (like how many times an enemy attacks per round, and so forth). But that's another topic.
TMC wrote:I think it's only a weekend's work.
This bears repeating: A weekend's worth? Really? Doesn't sound like very much work then. Kinda like making a 48-hour contest game.
Place Obligatory Signature Here
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

OK, well, glad to have some pressure, I guess.

The other day a feature which I estimated at 5 minutes took me about 3 hours. So I don't believe my own numbers. But I have already done a significant part.
Post Reply