Turn Script Help
chrisw70
30 Oct 2015, 21:10Hello - I have been trying to understand how to implement a turn script and then end it, so it does not keep repeating in a loop. I keep reading the forums and there's something about adding an "integer" or "counter" to make the turn script stop, but I can't find a visual example of how that is done through the GUI?
Simply, I'd just like each room to have a turn script which will print a message after a specified number of turns, and then stop. I only want it to rn when the player is in the room.
How can you make a tun script stop after it's started? Thanks in advance for any help.
Simply, I'd just like each room to have a turn script which will print a message after a specified number of turns, and then stop. I only want it to rn when the player is in the room.
How can you make a tun script stop after it's started? Thanks in advance for any help.
HegemonKhan
31 Oct 2015, 01:10this is a bit advanced and involves quite a few steps~things that you got to do... so please ask questions if you get stuck anywhere or need help with anything or don't understand something or etc etc etc
---------------------------------------
Turnscripts are like always running Functions (or Verbs, if you're not familiar with Functions yet)... well... when they are 'enabled' (a Boolean Attribute: true~false).
So, this is the answer to your question:
1A. add the Turnscripts to your desired rooms (for example):
click on 'roomX' Room Object on the left side, so it is highlighted, then (one way) at the top of the screen in the menu bar, click on 'Add', and select 'Turnscript', this will create~add a Turnscript into your 'roomX' (when Turnscripts are in rooms, they are 'local' Turnscripts, meaning that their scripts only apply~run~activate when you're in that room, and when the Turnscript is 'enabled' too, of course)
repeat the above for additional rooms, 'roomX+1', roomX+2', etc, of yours.
~~~~~~ OR ~~~~~~~
1B. due to me being unclear from your post, if you want the same scripts to be run~activated in EVERY~ALL of your game's rooms... then you'll just want to make a single 'global' Turnscript (as you don't want to be adding a Turnscript to every room in your game! This would be VERY BAD!)
to create~add a 'global' Turnscript, means that you do *NOT* add a Turnscript into a specific room, thus a way to ensure this is to do this:
click on the upper-left most 'Object' in your 'tree of stuff' on the left side of the screen, so it is highlighted, and then (one way) at the top of the screen, click on the 'Add', and then select 'Turnscript', which will create~add a global Turnscript to your game.
2. Setting up the Turnscript(s):
Name: whatever you want to call it, must be unique (no two names of anything can be the same, within the same scope and of the same data type, anyways)
[_] Enabled when the game begins: it explains itself, check this in, if you want the Turnscript to be immediately running~activating its scripts when the game begins. (if checked, this sets its 'enabled' Boolean Attribute to 'true'. In Code scripting: Turnscript_name.enabled = true. If not checked, then it sets its 'enabled' Boolean Attribute to 'false'. In code scripting: Turnscript_name.enabled = false)
Script: (add your scripts that the Turnscript runs constantly, when its 'enabled', and if local Turnscript, also when you're in its room)
-----------
Turnscripts (when 'enabled', and if local, also when in its room) run their scripts every internal turn (basically, this is whenever you click on something and~or hit enter when you've highlighted the command-text input box at the bottom of the screen, during game play)
------------
Since you want scripts to be based off of your turns, then you must create~add your own Attribute, as I'm not sure if you even can keep track of the internal turns directly (and if you can, no idea how to yet, lol).
By creating~adding your own Attribute, you can use (manipulate) it for what you want (increasing-counting it, and basing your messages off of its increasing-count-counting value).
so, we got two choices:
A. a local 'turn' Int (Integer) Attribute: add these attributes to each of your desired rooms
~OR~
B. a global 'turn' Int (Integer) Attribute: add this Attribute, either to your 'game' Game Object or your 'player' Player Object.
A. (example) 'roomX' Room Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: roomX)
Attribute Name: turns // or whatever you want to call it
Attribute Type: int // an integer (non-decimal) data type
Attribute Value: 0 // usually you want to start at 0 and count upwards for most things, but you can certainly start at say 100 and count downwards too
repeat this for each of your desired rooms
let's say in 'roomX+1' your 'turn' Int Attribute has the value (is at) '5', and in 'roomX+2' your 'turn' Int Attribute has the value (is at) '50', this is pefectly okay, as this is what 'local' means, they're independant~separate from each other.
B. (examples, see below)
'game' Game Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: game)
Attribute Name: turns
Attribute Type: int
Attribute Value: 0
~OR~
'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: player)
Attribute Name: turns
Attribute Type: int
Attribute Value: 0
-------------------------
now, back within, your Turnscript(s):
your LAST (bottom-most) added script must be:
add new script -> variables -> 'set a variable or attribute' Script -> (see below, we're going to do some code writing, hehe)
(depending on how you decided to set up the above, choose the correct script below)
// Object_name.Attribute_name = Value_or_Expression
// Object_name: player
// Attribute_name: turns
// Expression (Attribute_VARIABLE Addition_Operation Value): player.turns + 1
set variable player.turns = [EXPRESSION] player.turns + 1
// you don't have to do '+ (addition)', nor '1 (value)', you could do, for example, ' * 5 (multiply by 5)', see below:
// set variable player.turns = [EXPRESSION] player.turns * 5
// by the way, working directly in code, it's actual form is this (a bit of a difference than how the GUI~Editor coding does it):
// player.turns = player.turns + 1
OR
set variable game.turns = [EXPRESSION] game.turns + 1
OR (for your various rooms, replace the code with the proper names you've given your room~s):
set variable roomX.turns = [EXPRESSION] roomX.turns + 1
--
set variable roomX+1.turns = [EXPRESSION] roomX+1.turns + 1
---
etc etc etc
---------------
this will cause your 'turns' to increase by 1, after every internal turn.
-------------
as for your desired ('msg' ~ 'Print a message' Script) message script:
within your Turnscripts, BEFORE (ABOVE) your 'Object_name.turns = Object_name.turns + 1' Script, add in these scripts (using 'game' as the example):
add new script -> scripts -> 'if' Script -> (more GUI~Editor coding, hehe) -> if [Expression] game.turns = 5
// or you can do: if [expression] game.turns > 5
-> then -> add new script -> output -> 'print a message' Script -> (write what you want here: if you do [message] option, then you just write a normal sentence, aka 'text', for your message, if you choose the [expression] option, then you can do VARIABLES with your text - you'll probably need help for this if you're new to quest and especially programming~coding)
add new script -> variables -> 'set a variable or attribute' Script -> set variable game.turns = [expression] game.turns + 1
repeat and adjust the coding, for each of your rooms, if doing local turnscripts.
-------------
lastly... you want to display the 'turns' to the person playing the game...
if you're doing a global Turnscript, using 'game' or 'player' Objects, then you can use their 'STATUS ATTRIBUTES' for the displayment during game play.
(I can link you to a guide I made on them if interested or if can't find it on your own, it's in the 'libraries and code samples' forum board section, called ~ 'attributes' ~ I discuss attributes and status attribute in it)
if you're using local turnscripts, then it's a bit different to display your rooms' 'turns'... the easiest would be using a message script in your rooms' turnscripts... other ways, would be more advanced~complex~hard to do...
---------------------------------------
Turnscripts are like always running Functions (or Verbs, if you're not familiar with Functions yet)... well... when they are 'enabled' (a Boolean Attribute: true~false).
So, this is the answer to your question:
1A. add the Turnscripts to your desired rooms (for example):
click on 'roomX' Room Object on the left side, so it is highlighted, then (one way) at the top of the screen in the menu bar, click on 'Add', and select 'Turnscript', this will create~add a Turnscript into your 'roomX' (when Turnscripts are in rooms, they are 'local' Turnscripts, meaning that their scripts only apply~run~activate when you're in that room, and when the Turnscript is 'enabled' too, of course)
repeat the above for additional rooms, 'roomX+1', roomX+2', etc, of yours.
~~~~~~ OR ~~~~~~~
1B. due to me being unclear from your post, if you want the same scripts to be run~activated in EVERY~ALL of your game's rooms... then you'll just want to make a single 'global' Turnscript (as you don't want to be adding a Turnscript to every room in your game! This would be VERY BAD!)
to create~add a 'global' Turnscript, means that you do *NOT* add a Turnscript into a specific room, thus a way to ensure this is to do this:
click on the upper-left most 'Object' in your 'tree of stuff' on the left side of the screen, so it is highlighted, and then (one way) at the top of the screen, click on the 'Add', and then select 'Turnscript', which will create~add a global Turnscript to your game.
2. Setting up the Turnscript(s):
Name: whatever you want to call it, must be unique (no two names of anything can be the same, within the same scope and of the same data type, anyways)
[_] Enabled when the game begins: it explains itself, check this in, if you want the Turnscript to be immediately running~activating its scripts when the game begins. (if checked, this sets its 'enabled' Boolean Attribute to 'true'. In Code scripting: Turnscript_name.enabled = true. If not checked, then it sets its 'enabled' Boolean Attribute to 'false'. In code scripting: Turnscript_name.enabled = false)
Script: (add your scripts that the Turnscript runs constantly, when its 'enabled', and if local Turnscript, also when you're in its room)
-----------
Turnscripts (when 'enabled', and if local, also when in its room) run their scripts every internal turn (basically, this is whenever you click on something and~or hit enter when you've highlighted the command-text input box at the bottom of the screen, during game play)
------------
Since you want scripts to be based off of your turns, then you must create~add your own Attribute, as I'm not sure if you even can keep track of the internal turns directly (and if you can, no idea how to yet, lol).
By creating~adding your own Attribute, you can use (manipulate) it for what you want (increasing-counting it, and basing your messages off of its increasing-count-counting value).
so, we got two choices:
A. a local 'turn' Int (Integer) Attribute: add these attributes to each of your desired rooms
~OR~
B. a global 'turn' Int (Integer) Attribute: add this Attribute, either to your 'game' Game Object or your 'player' Player Object.
A. (example) 'roomX' Room Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: roomX)
Attribute Name: turns // or whatever you want to call it
Attribute Type: int // an integer (non-decimal) data type
Attribute Value: 0 // usually you want to start at 0 and count upwards for most things, but you can certainly start at say 100 and count downwards too
repeat this for each of your desired rooms
let's say in 'roomX+1' your 'turn' Int Attribute has the value (is at) '5', and in 'roomX+2' your 'turn' Int Attribute has the value (is at) '50', this is pefectly okay, as this is what 'local' means, they're independant~separate from each other.
B. (examples, see below)
'game' Game Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: game)
Attribute Name: turns
Attribute Type: int
Attribute Value: 0
~OR~
'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)
(Object Name: player)
Attribute Name: turns
Attribute Type: int
Attribute Value: 0
-------------------------
now, back within, your Turnscript(s):
your LAST (bottom-most) added script must be:
add new script -> variables -> 'set a variable or attribute' Script -> (see below, we're going to do some code writing, hehe)
(depending on how you decided to set up the above, choose the correct script below)
// Object_name.Attribute_name = Value_or_Expression
// Object_name: player
// Attribute_name: turns
// Expression (Attribute_VARIABLE Addition_Operation Value): player.turns + 1
set variable player.turns = [EXPRESSION] player.turns + 1
// you don't have to do '+ (addition)', nor '1 (value)', you could do, for example, ' * 5 (multiply by 5)', see below:
// set variable player.turns = [EXPRESSION] player.turns * 5
// by the way, working directly in code, it's actual form is this (a bit of a difference than how the GUI~Editor coding does it):
// player.turns = player.turns + 1
OR
set variable game.turns = [EXPRESSION] game.turns + 1
OR (for your various rooms, replace the code with the proper names you've given your room~s):
set variable roomX.turns = [EXPRESSION] roomX.turns + 1
--
set variable roomX+1.turns = [EXPRESSION] roomX+1.turns + 1
---
etc etc etc
---------------
this will cause your 'turns' to increase by 1, after every internal turn.
-------------
as for your desired ('msg' ~ 'Print a message' Script) message script:
within your Turnscripts, BEFORE (ABOVE) your 'Object_name.turns = Object_name.turns + 1' Script, add in these scripts (using 'game' as the example):
add new script -> scripts -> 'if' Script -> (more GUI~Editor coding, hehe) -> if [Expression] game.turns = 5
// or you can do: if [expression] game.turns > 5
-> then -> add new script -> output -> 'print a message' Script -> (write what you want here: if you do [message] option, then you just write a normal sentence, aka 'text', for your message, if you choose the [expression] option, then you can do VARIABLES with your text - you'll probably need help for this if you're new to quest and especially programming~coding)
add new script -> variables -> 'set a variable or attribute' Script -> set variable game.turns = [expression] game.turns + 1
repeat and adjust the coding, for each of your rooms, if doing local turnscripts.
-------------
lastly... you want to display the 'turns' to the person playing the game...
if you're doing a global Turnscript, using 'game' or 'player' Objects, then you can use their 'STATUS ATTRIBUTES' for the displayment during game play.
(I can link you to a guide I made on them if interested or if can't find it on your own, it's in the 'libraries and code samples' forum board section, called ~ 'attributes' ~ I discuss attributes and status attribute in it)
if you're using local turnscripts, then it's a bit different to display your rooms' 'turns'... the easiest would be using a message script in your rooms' turnscripts... other ways, would be more advanced~complex~hard to do...
HegemonKhan
31 Oct 2015, 01:13oops... I forgot to tell you how to 'enable~disable' your Turnscripts....
you can do so from where-ever and~or how~ever you want to within your game, you just have to select these scripts:
(run as script) -> add new script -> Turn Scripts -> 'enable turn script ~ disable turn script' Scripts -> (type in the name of the desired turnscript in the 'enable~disable turn script' text box)
------
also, you may want to return~reset your (various) 'turns' Attribute(s) back to '0' (such as after your message script), which can be done via this script:
(run as script) -> add new script -> variables -> 'set a variable or attribute' Script -> (see below, an example only, adjust code as needed, aka: just change 'game' to the proper Object's name)
set variable game.turns = [Expression] 0
-----
also, be aware that you can do this (example) type of design (sorry for the code, but it's quick for me ~ hopefully you can understand the design concept, of multiple responses~effects~events based upon increasing values of the 'turn' counting, of what I'm trying to convey with it):
----
if you need help on this (more explanation), let me know
you can do so from where-ever and~or how~ever you want to within your game, you just have to select these scripts:
(run as script) -> add new script -> Turn Scripts -> 'enable turn script ~ disable turn script' Scripts -> (type in the name of the desired turnscript in the 'enable~disable turn script' text box)
------
also, you may want to return~reset your (various) 'turns' Attribute(s) back to '0' (such as after your message script), which can be done via this script:
(run as script) -> add new script -> variables -> 'set a variable or attribute' Script -> (see below, an example only, adjust code as needed, aka: just change 'game' to the proper Object's name)
set variable game.turns = [Expression] 0
-----
also, be aware that you can do this (example) type of design (sorry for the code, but it's quick for me ~ hopefully you can understand the design concept, of multiple responses~effects~events based upon increasing values of the 'turn' counting, of what I'm trying to convey with it):
<turnscript name="global_turnscript">
<enabled />
<script>
if (game.turns = 5) {
msg ("5 game turns have passed")
} else if (game.turns = 10) {
msg ("10 game turns have passed")
} else if (game.turns = 25) {
player.strength = player.strength + 5
msg ("Due to reaching turn 25, you get a bonus of +5 strength")
} else if (game.turns = 50) {
msg ("50 game turns have passed")
} else if (game.turns >= 100) {
msg ("You've played the game beyond its turn limit of 100, so, to keep playing, the game turns are being reset back to zero for you.")
game.turns = 0
}
game.turns = game.turns + 1
</script>
</turnscript>
----
if you need help on this (more explanation), let me know
chrisw70
31 Oct 2015, 16:23Thanks, I get how to implement the turn-script globally (outside of specific rooms) as per your example, but when I have tried to modify the code example you gave and apply it to a specific room, I cannot get it to work right. So, using my example game code here, how would you integrate your code example so when the player enters the room "Castle" a turn-script runs and prints msg's after a specific number of turns only while the player is in the room "Castle," and then resets itself to 0 so it runs again from the start the next time the player enters the room?
If you could show me how to integrate the code here in this example it would be easier to understand how i works when I can run the example game and see in the code and GUI how everything was structured...
Thanks again!
If you could show me how to integrate the code here in this example it would be easier to understand how i works when I can run the example game and see in the code and GUI how everything was structured...
Thanks again!
<!--Saved by Quest 5.6.5621.18142-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="turn script sample">
<gameid>a9cea17b-af4a-4145-9f40-6002bffc2c7c</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
</game>
<object name="Road">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="Forest">
<inherit name="southdirection" />
</exit>
</object>
<object name="Forest">
<inherit name="editor_room" />
<exit alias="north" to="Road">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Lake Shore">
<inherit name="southdirection" />
</exit>
</object>
<object name="Lake Shore">
<inherit name="editor_room" />
<exit alias="north" to="Forest">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Castle">
<inherit name="southdirection" />
</exit>
</object>
<object name="Castle">
<inherit name="editor_room" />
<exit alias="north" to="Lake Shore">
<inherit name="northdirection" />
</exit>
</object>
</asl>
HegemonKhan
31 Oct 2015, 17:34I've separated out the part (you 'Castle' Room Object 'creation' tag block) that I've edited, so you can clearly see what I've done:
(quest doesn't care about empty lines ~ though it's not that pretty ~ once you see what I've done you should remove my empty lines and my, comment: //, lines)
(I also just used the room's built-in 'onexit' Script, for returning~resetting your turns back to zero, as this is the easiest~simpliest way to do so: upon entering for first time, the 'Castle.turns' starts at 0, after each action~click and~or typing+enter you do as the person playing the game, the turns increase by 1, and upon leaving the 'Castle' room, the 'Castle.turns' are reset back to 0, so when you re-enter the room, they'll be starting at zero again)
(in the GUI~Editor, you can access~find the 'onexit' Script via: 'Castle' Room Object -> 'Scripts' Tab -> 'onexit' Script)
-------------------------
here's the code, without any empty lines, nor any comment lines:
------------------------
if it doesn't work, let me know, and I'll fix it up, so it does.
(it'a easy to make mistakes~typos~etc, and I may not have some syntax correct, easy things to fix up)
(quest doesn't care about empty lines ~ though it's not that pretty ~ once you see what I've done you should remove my empty lines and my, comment: //, lines)
(I also just used the room's built-in 'onexit' Script, for returning~resetting your turns back to zero, as this is the easiest~simpliest way to do so: upon entering for first time, the 'Castle.turns' starts at 0, after each action~click and~or typing+enter you do as the person playing the game, the turns increase by 1, and upon leaving the 'Castle' room, the 'Castle.turns' are reset back to 0, so when you re-enter the room, they'll be starting at zero again)
(in the GUI~Editor, you can access~find the 'onexit' Script via: 'Castle' Room Object -> 'Scripts' Tab -> 'onexit' Script)
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="turn script sample">
<gameid>a9cea17b-af4a-4145-9f40-6002bffc2c7c</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
</game>
<object name="Road">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="Forest">
<inherit name="southdirection" />
</exit>
</object>
<object name="Forest">
<inherit name="editor_room" />
<exit alias="north" to="Road">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Lake Shore">
<inherit name="southdirection" />
</exit>
</object>
<object name="Lake Shore">
<inherit name="editor_room" />
<exit alias="north" to="Forest">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Castle">
<inherit name="southdirection" />
</exit>
</object>
<object name="Castle">
<inherit name="editor_room" />
<exit alias="north" to="Lake Shore">
<inherit name="northdirection" />
</exit>
// your Castle's 'turns' Int Attribute:
<attr name="turns" type="int">0</attr>
// upon leaving the room, your Castle's 'turns' are reset to 0:
<onexit type="script">
Castle.turns = 0
</onexit>
// the local Turnscript (aka: the Castle's Turnscript):
<turnscript name="test_turnscript">
// this is the shortened syntax for setting 'enabled' to 'true',
// this makes the Turnscript active immediately upon
// entering the 'Castle' Room Object:
<enabled />
<script>
// there's better ways to display your castle's turns,
// but this is just a sample code for you:
msg ("Castle Turn: " + Castle.turns)
// adjust~change the Values (5,10,etc) as you want:
if (Castle.turns = 5) {
msg ("turn 5")
} else if (Castle.turns = 10) {
msg ("turn 10")
}
// etc more or less 'else ifs' as needed
// optional: an 'else' if needed
// this increases your turns:
Castle.turns = Castle.turns + 1
</script>
</turnscript>
</object>
</asl>
-------------------------
here's the code, without any empty lines, nor any comment lines:
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="turn script sample">
<gameid>a9cea17b-af4a-4145-9f40-6002bffc2c7c</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
</game>
<object name="Road">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="Forest">
<inherit name="southdirection" />
</exit>
</object>
<object name="Forest">
<inherit name="editor_room" />
<exit alias="north" to="Road">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Lake Shore">
<inherit name="southdirection" />
</exit>
</object>
<object name="Lake Shore">
<inherit name="editor_room" />
<exit alias="north" to="Forest">
<inherit name="northdirection" />
</exit>
<exit alias="south" to="Castle">
<inherit name="southdirection" />
</exit>
</object>
<object name="Castle">
<inherit name="editor_room" />
<exit alias="north" to="Lake Shore">
<inherit name="northdirection" />
</exit>
<attr name="turns" type="int">0</attr>
<onexit type="script">
Castle.turns = 0
</onexit>
<turnscript name="test_turnscript">
<enabled />
<script>
msg ("Castle Turn: " + Castle.turns)
if (Castle.turns = 5) {
msg ("turn 5")
} else if (Castle.turns = 10) {
msg ("turn 10")
}
Castle.turns = Castle.turns + 1
</script>
</turnscript>
</object>
</asl>
------------------------
if it doesn't work, let me know, and I'll fix it up, so it does.
(it'a easy to make mistakes~typos~etc, and I may not have some syntax correct, easy things to fix up)
chrisw70
01 Nov 2015, 00:41Works great I tried it out under a variety of different scenarios and I believe I can adapt it now to fit a lot of different needs, thanks HK!