Any suggestion on how to make this script more fluid?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

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

Any suggestion on how to make this script more fluid?

Post by sheamkennedy »

I have a script I'm making such that when I press "Z" on the keyboard, my hero in my party cycles to the next party member that is present if any exist. The script works fine but only carries itself out when my player is stationary. I'd like to make the code so that the player may switch character while in motion. I figure this would cause some sort of tile misalignment so thought maybe someone could instead suggest a way to make it so the code acknowledges the keypress, then changes characters once the character is aligned with the next tile.

Here's the original working code:
EDIT: I was trying to post my code but the forum isn't letting me. Maybe it's a syntax error thats throwing things out of order, sorry. If my code is absolutely necessary to solve this problem I'll find a way to post it tomorrow or something.
Last edited by sheamkennedy on Tue Mar 03, 2015 7:31 am, edited 7 times 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
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Try turning off HTML and BB Code, sometimes that works!
User avatar
FnrrfYgmSchnish
Metal Slime
Posts: 741
Joined: Thu Jun 18, 2009 4:37 am
Location: Middle of Nowhere

Post by FnrrfYgmSchnish »

Or post the script inside code tags.

Code: Select all

[code]Insert your script here.[/code]
Last edited by FnrrfYgmSchnish on Tue Mar 03, 2015 9:08 am, edited 1 time in total.
FYS:AHS -- Working on Yagziknian NPC walkabout sprites
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Turning off bbcode isn't necessary, but you need to turn off html if your script contains the < and > characters.

I'd never considered the case of changing the party while the heroes are moving. However, looking at the code it looks like doing that should be no problem, as the swapped hero takes the position and even the speed of the previous hero (which could be considered a bug). What happens if you try it?
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 »

Thanks, the html being enabled was messing it up. Here's the code I currently have:

Code: Select all

    if&#40;key is pressed&#40;key&#58;Z&#41;&#41; then&#40;
      if&#40;isClimbing == 0&#41; then&#40;
        
        #suspend player
        #wait for hero &#40;me&#41;
        
        ### Cycle through players if they are in the 4 main slots
        if &#40;leader == hero&#58;Rodion&#41; then&#40;
          #Checks if character exists in 4 main slots
          if &#40;&#40;find hero&#40;hero&#58;Taras&#41; >= 0&#41; && &#40;find hero&#40;hero&#58;Taras&#41; <= 3&#41;&#41; then&#40;
            swap by name &#40;hero&#58;Taras,hero&#58;Rodion&#41;
            embiggen now
          &#41;  
        &#41;
        else if &#40;leader == hero&#58;Taras&#41; then&#40;
          #Checks if character exists in 4 main slots
          if &#40;&#40;find hero&#40;hero&#58;Rodion&#41; >= 0&#41; && &#40;find hero&#40;hero&#58;Rodion&#41; <= 3&#41;&#41; then&#40;
            swap by name &#40;hero&#58;Rodion,hero&#58;Taras&#41;
            embiggen now
          &#41;  
        &#41; 
      #resume player
      &#41; 
    &#41;
This code only seems to work if my hero is aligned with the grid even though there is nothing specifying the code to do so. Thus if I am in between tiles and press "Z" then it doesn't execute. What I would like it to do in that case is wait until I align with the next tile, then execute.

I had an idea that if I suspend the player, wait for hero (this should wait for the hero to align), then execute code and resume the player. This didn't work though...

I figured if I made an each-step script I could handle this case with a variable that is enables by the keypress, then checked for by the each-step script. This idea seems clunky though and I feel like it might be vulnerable to mishaps. I'm open to hearing other ideas before even doing this.

EDIT: After further inspection of this code by adding a long wait function in to it I was able to determine that on-keypress scripts seem to only trigger when the hero is aligned, not in mid step. I checked the plotscripting dictionary to see if this sort of behaviour is to be expected for "key is pressed" but did not find it mentioned anywhere. Due to this I believe that there could be something wrong with how "key is pressed" functions. I am curious to know if there is a way around this since I believe it would make my second coding idea not work either due to the variable not being turned on mid step...
Last edited by sheamkennedy on Tue Mar 03, 2015 1:49 pm, edited 5 times 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
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 »

Disregard everything, I figured it out!

For those interested I made a stupid mistake long ago in my code which brought this on.

I had the following at the top of my onkeypress script:

Code: Select all

  if&#40;hero is walking&#40;me&#41; == false&#41; then&#40;
    set hero speed&#40;me, 4&#41;
    
...which had no end bracket. Followed by all my key press scripts. Thus it was checking to see if my character was standing still. Long ago I must have added an end bracket after every keypress condition in order to allow he script to compile, then didn't have a problem with keypresses until now... very silly.
⊕ 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
Post Reply