Wait ticks freeze the main loop

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

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Wait ticks freeze the main loop

Post by Foxley »

This is in regards to the Zelda-like. I'm having difficulty coming up with a way to have player actions that don't totally freeze up the main "while true do" loop, so that other things can happen, e.g. a script for an enemy taking damage and being knocked back when the sword slice hits them.

Should I just use wait ticks for one thing, like player actions, then jury rig 'fake' wait ticks by using 1 tick long timers for everything else?
User avatar
kylekrack
Liquid Metal Slime
Posts: 1242
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Look into using timers and timer loops (where a set timer() in a script calls that script at the end). If the processes you're trying to do are too complex to use timers, I'm not sure about other solutions.

You shouldn't have to use wait commands other than your wait(1) at the end of each while loop and during cutscenes/textbox scenes. From my experience, using timers takes a lot of planning, at least compared to waits, if you want it to work right on the first try. It ends up being worth it, however. Timers allow the working scripts to essentially take care of themselves.

EDIT: Actually, have you looked at scripts for other OHR zelda-likes? I know there are some out there. I'd check out how they do it before trying anything yourself.
Last edited by kylekrack on Fri Nov 18, 2016 10:15 pm, edited 1 time in total.
My pronouns are they/them
Ps. I love my wife
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

You running timing variables that increment every loop and then you Check their value
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

For example, suppose you make NPC extra value 1 be an ID number indicating what kind of animation the monster is doing, like 1=attacking, 2=hurt

Then make NPC extra value 2 be which step of the animation that the monster is currently on

So each tick you would check each monster, and update their sprite according to those values.

(I do an even more elaborate version of that sort of thing in many of my games. If you want to see full-on fake-object-oriented-scripting, check out my scripts for Don't Eat Soap or Vorpal Florist)
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Alright, I'll have to check those out. I'm still a scripting idiot (but I'm making progress!)
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

Did you ever look at my somekindaninja script?
You can even use you as a base to start from.
Complete with pixel based movement, sword attack, sword charge up blast, and, enemies
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The script you posted before for the camera scrolling is very easy to convert to timers. You just split it into two scripts: the setup part, which calls:

Code: Select all

script, eachtick screen edge check, begin
  screen edge check 
  set timer(0,0,1,@eachtick screen edge check)  #change id
end
However, in a zelda-like it's likely that you'll want to have multiple other things happening at the same time, so will end up needing to do things as other people have suggested. (Script multitasking can't come quickly enough!)
Last edited by TMC on Sat Nov 19, 2016 12:05 am, edited 1 time in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Spoonweaver wrote:Did you ever look at my somekindaninja script?
You can even use you as a base to start from.
Complete with pixel based movement, sword attack, sword charge up blast, and, enemies
I'd like to have a look. Could I have a link to it if you don't mind?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Interesting. I'll try to rewrite my scripts so it updates things per tick.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

I'm probably just going to use timers, I can't wrap my head around how to rewrite what I've already done in terms of making values update every tick. It'd probably be March by the time I even got the engine working if I did that, and I'd rather work on making an actual game instead.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Trying to use timers became a hideous mess really fast and none of it worked, so now I'm going to try (i.e. struggle) to work with values per tick.

I'm working on some pseudocode to try to get an understanding of how to manage values per tick/frame, if someone could give feedback on IRC later tonight I'd appreciate it.
Post Reply