Login
Remember
IF Answers
Ask a Question

# Quest: Having trouble with Turn Scripts.

0 votes
56 views
asked Jul 8 in Authoring by Lewis Steele

Heya all

I've been trying to use turn scripts, to little success. I tried to make a night/day cycle, where after 5 turns it would say 'Night falls' or 'Day breaks' and then set the flag Night or day. However, it would then print 'Night falls' on every turn. I even set into the Turn Script 'Disable Turn Script 'Night' - but it still printed.

I solved that with instead putting a timer, for 60 seconds of day, and 60 seconds of night.

Now I'm trying to make a turn script so that when the player takes 5 turns, they are tired and need to sleep before they can do anything.

I've made a Turn Script in the game, called Tired.
It's script in the editor is:

After [number] 5 turns
[Run Script]
Print message: 'You're tired'
Set flag [object] [player] [flag name] Tired
Disable turn script [Tired]

Still I'm getting 'You are tired' on every turn.

Any advice? (If I'm making any sense here)

- quest
- turn-script

## 1 Answer

0 votes
answered Jul 10 by hegemonkhan (161 points)
edited Jul 10 by hegemonkhan

the Turnscript itself, unlike the Timer, doesn't have an interval (every X, do scripts) option. This is the one nice thing about the Timer, though unfortunately working with real time (the Timer) is messy and difficult.

You can create an interval effect with Turnscripts, but it takes some additional steps...

Turnscript is like an always activating global (aka: not tied to a specific Object) Verb, or a Function (though if you're new to quest and~or especially to coding ~ game making) you may not have worked with Functions yet, whereas due to using the GUI~Editor, you've likely used its Verbs.

Basically, in another way of saying the above, this is what a Turnscript is:

do the (added) scripts in the Turnscript on EVERY internal turn (any action~click you do while playing the game).

anyways.... here's a way of setting up an interval effect with a Turnscript:

we first need a 'counting~counter' Attribute:

'game' Game Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: game)

    Attribute Name: day_night_counter

Attribute Type: int (integer)
Attribute Value: 0

this is going to be increased by 1 after every action: 0 -> 1 -> 2 -> 3 -> 5 -> etc, which we do in the Turnscript, along with all the other stuff we need to do in the Turnscript, so now ...

and if you haven't, your 'day~night' Boolean Attribute too:

'game' Game Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: game)
Attribute Name: night_time
Attribute Type: boolean
Attribute Value: false*

*choose 'false' if you want to start your game during the day, or choose 'true' if you want to start the game during the night

conceptual logic of Boolean flagging:

    game.night_time = true ---> It is night time
    game.night_time = false ---> It is day time
    if (not game.night_time = false) ---> It is night time
    if (not game.night_time = true) ---> It is day time

    ~OR (using a different name for the Boolean Attribute: day_time) ~

    game.day_time = false ---> It is night time
    game.day_time = true ---> It is day time
    if (not game.day_time = false) ---> It is day time
    if (not game.day_time = true) ---> It is night time

the Turnscript's setup: (credit goes to Pixie for this design)

we need this to be a global Turnscript (aka: not tied to a specific room), so to make a global Turnscript:

on the left side's 'tree of stuff', right click on the upper-left-most 'Objects', and select 'add turnscript'

now for the Turnscript:

    Name: global_turnscript

'Enabled' check box: have it be checked in
Scripts: (see below)

    add a~new script -> scripts -> 'if' Script -> if [expression] game.day_night_counter = 5

    -> then -> add a~new script -> variables -> 'set a variable or attribute' Script -> set variable game.day_night_counter = [expression] 0

    -> add a~new script -> scripts -> 'if' Script -> if [expression] game.night_time = true

    ->-> then -> add a~new script -> variables -> 'set a variable or attribute' Script -> set variable game.night_time = [expression] false

    ->-> add a~new script -> output -> 'print a message' Script -> print [message] It is now day time.

    -> else add -> add a~new script -> scripts -> 'if' Script -> if [expression] game.night_time = false

    ->-> then -> add a~new script -> variables -> 'set a variable or attribute' Script -> set variable game.night_time = [expression] true

    ->-> add a~new script -> output -> 'print a message' Script -> print [message] It is now time time.

    add a~new script -> variables -> 'set a variable or attribute' Script -> set variable game.day_night_counter = [expression] game.day_night_counter + 1

explanation of the scripts:

    if the game.day_night_counter = 5, reset it back to zero (game.day_night_counter = 0), and then, if it is night (game.night_time = true), then it changes to day (game.night_time = false), or else if it is day (game.night_time = false), then it changes to night (game.night_time = true). And, If the game.day_night_counter was not 5, then just ignore this part~paragraph entirely, jumping down to the line below.

    Lastly, increase the game.day_night_counter by 1 (game.day_night_counter = game.day_night_counter + 1).

err... this was for the day-night time changing... but hopefully you can use this also for your tiredness~need to sleep too...

if you want the '5' counting do be the interval of day-night changing, than have your 'tiredness' occur at like '20' (or whatever) of the day-night counter Attribute.

I'll have to think about this a bit more... but see if you can get soemthing working first, and if not, then let me know and I'll help with this second part to what you want.

let me know if you need any help or explanation with anything.

## Related questions

- Stopping timer Event with Key Press
- Is there a limit to the length of a script in Quest?
- How can I check the user's command?
- How do I turn a Quest game into an app?
- Quest Problem with "Get Input" in a loop

...