- whatislove00 1m https://www.youtube.com/watch?time_continue=795&v=fpbOEoRrHyU
- villa 1s
- JustSomeGuy 6s
- JMo 7m You're a single shake man! No time for the follow-up jiggle!
- SpecialK 13s https://youtu.be/6ZfuNTqbHE8
- Evangeline 4s
- Revex 1m
- Kisaki 15s Don't Stop Music...
- Ostheim 1m
- YourLeftHand 31m
- SpaceLatency 5s
- NovaQuinn 2m
- Atheran 39s
- Vera 14s youtu.be/wmOw-jplSMk
- ComradeNitro 16m
- Speccy 1h
- Marioanius 28s Hamilton wrote, the other 51!
- Valentine 14s
- jwimpeney 43s
- CellDweller 35s
- jsmith225 27m
- waddlerafter 22s
- Ryuzaki4Days 3m
- Crucioux343 2m
- Neekly 3m
- Baron17 1m
- Melpothalia 2m
- Lycanthorph 1m
- Evie 0s
- Malanth 1m
- Storm 1m
- Rigo 2s
- Newbs21 1m We're all crazy here!
- Cyberpunker 24m
- Grey0 1m
- BCingyou 12s
- FancyPenguin 12s
- Azelle 11h
a Cerberus 11h Head Builder & GM when I need to
- wiebman 1h
- SacredWest 7h
- Chrissl1983 40m Really enjoying this awesome game to the fullest!
j Johnny 1h New Code Written Nightly. Not a GM.
And 27 more hiding and/or disguised
Connect to Sindome @ moo.sindome.org:5555 or just Play Now

Part 3: Script Flow Control
How to make your scripts dance.

Up until now all your scripts have been 'linear' in nature. That is to say they start at the first line, end on the last line, and unless they encounter an if, it executes every line in between in order.

However it is becoming necessary to write scripts which have more control over their 'flow'. That is to say they have the need to go not just forwards, but to skip forwards and backwards.

The first command to help you do this is: stop

Stop makes the script end. Finished. Done. Even if it's in the middle of the script.

You'll see why this is very important in just a second.

To allow you to jump to specific locations in your script you can denote 'jump points' in your script with the 'label' command. When you use the label command and pass it a string, you can later (or sooner) 'jump' to that label.

Doing an endless loop using a label and jump would look like this:

(WARNING! THIS IS AN EXAMPLE! DO NOT DO THIS!)
label "begining"
tell %player "Hello!"
jump "begining"

This would tell the player Hello! over and over and over and over again until a Wizard came and killed the task, and probablly killed your charcater as well for writing such a harmful script.

Now, the ability to jump in and of itself is pretty powerful. It's intended purpose is to allow you to do things like start the script over (A LIMITED NUMBER OF TIMES), or skip over entire parts of the script.

However, if you only use label and jump to do complex things, your logic can become -very- confusing.

So we introduce the concept of 'start' and 'finish'.

start works exactly like jump in that it takes a label name and jumps you to that label. What's different about start is it -remembers- where you are in the script, and upon encountering a 'finish', returns you to that place.

Let's try an example.

uses $default_script
//Doin some stuff here
start "blowjob"
tell %player "And that's how you give a blowjob."
//Note the use of stop here to end the script before we go into the 'blowjob' code
stop

label "blowjob"
//tell the player how to give a good blowjob here
finish

So, what happens there is we 'do some stuff' per the comment, then -remember- where we are and jump to the label blowjob. Upon encountering the 'finish' statement, we go BACK to where we 'start'ed "blowjob", and continue on from there until we encounter the 'stop'.

You can also do nested starts, like a start in blowjob that takes you elsewhere, and the first finish will return you to back inside blowjob, while the second finish will take you back to the begining. Thus you can come up with very complex scripts which do all kinds of interesting things.

Here's a rather contrived but valid example of how you might use this:

uses $default_script
label "begining"
tell %player "Please choose from the following options. For a burger, say burger. For fries, say fries. To end this, say goodbye."
waitfor "response"
if match %response "burger"
�start "burger"
�jump "begining"
elseif match %response "fries"
�start "fries"
�jump "begining"
elseif match %response "goodbye"
�tell %player "Goodbye!"
else
�tell %player "That's not one of the options. Please try again."
�jump "begining"
endif
stop

label "burger"
//do burger stuff here
finish

label "fries"
tell %player "Do you want curly or regular?"
waitfor "response"
if match %response "curly"
�start "curly"
elseif match %response "regular"
�start "regular"
else
�tell %player "Please choose from the following options:
�jump "fries"
endif
finish

label "curly"
//Do curly fries here
finish

label "regular"
//Do regular fries here
finish


As you can see, with the creative use of jump and start you can do some really complex flow control which reads rather well.

Now I suggest you take the use of these things VERY SERIOUSLY as their improper use can REALLY fuck things up in a BIG way if your not VERY careful. It's very easy to write crappy code with this. The key lies in modularity and simplicity. KISS: Keep it simple stupid.

Any questions, comments, or screams of agony?

-Kevlar

PS: Many of you will reconize this as a 'function' or 'sub-routine'. Yes, it is in fact just a simple stack machine, the premise on which all modern computing is based. I never claimed to invent the concept. I'm just making really effective use of it.

(Edited by Kevlar at 1:26 pm on Mar. 15, 2003)