Using score to trigger event
michaelsahn
05 Mar 2014, 04:03Hello again -
I want to create a global script that moves an object into a room when a score is greater than an integer.
I am having the player move from room to room, completing tasks, which raises his score. When the score is greater than a certain number, I'd like an object to move into the room the player is in.
Any guidance is greatly appreciated. Thanks again!
Mike
I want to create a global script that moves an object into a room when a score is greater than an integer.
I am having the player move from room to room, completing tasks, which raises his score. When the score is greater than a certain number, I'd like an object to move into the room the player is in.
Any guidance is greatly appreciated. Thanks again!
Mike
HegemonKhan
05 Mar 2014, 05:05I believe the built-in Attribute Name is "score" (game.score ~ this means, aka is letting you know, that the "game" Object holds~contains the "score" Attribute), so this is what you do:
In the GUI~Editor:
there's two ways~methods to do this
Way~Method One:
1. click on "Object" (the upper left most "Object" in the ' tree of stuff ' ~ see below in the code box), so that it is highlighted (this ensures that the Turnscript we're going to create~add, will be a global~game Turnscript ~ meaning that it'll apply anywhere~everywhere, regardless of what room the player is in, and not a Turnscript that only applies to a specific room).
2. at the top of the screen, in the menu bar, you want to click on "Add" (or whatever), and choose to add a "Turnscript"
Turnscript Name: global_turn_script // this is just my example (personal system~structure of) a name~label for it
// you'll probably want the Turnscript enabled at the start of the game (have the box checked), or if not... let me know, and I'll help you with setting it up to when~where you want it to be enabled, and obviously leave (or change it so that) the box UN-checked off.
in the Turnscript, you want to add this script:
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score = 10 // an example only
-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score = 20 // an example only
-> then, add a script -> // whatever script
Way~Method Two:
"game" Object -> Attributes (Tab) -> Attributes -> Add ->
// this is a special built-in Script Attribute name: changedAttribute_Name
// whenever your "game.score=number_amount" changes its Value (its number_amount), then its Script is run
Attribute Name: changedscore
Attribute Type: Script
Attribute Value: // see below
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score = 10 // an example only
-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score = 20 // an example only
-> then, add a script -> // whatever script
-------------
if you want to use "greater than" with your "score", then you'll need to add in this ("firsttime") to your scripting:
(I'm not sure what script category "firsttime" is under)
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score >= 10 // an example only
-> then, add a script -> ?Scripts? -> Firsttime ->
->-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score >= 20 // an example only
-> then, add a script -> ?Scripts? -> Firsttime ->
->-> then, add a script -> // whatever script
In the GUI~Editor:
there's two ways~methods to do this
Way~Method One:
1. click on "Object" (the upper left most "Object" in the ' tree of stuff ' ~ see below in the code box), so that it is highlighted (this ensures that the Turnscript we're going to create~add, will be a global~game Turnscript ~ meaning that it'll apply anywhere~everywhere, regardless of what room the player is in, and not a Turnscript that only applies to a specific room).
the default new game's ' tree of stuff ' appearance
Objects <----- you want this to be highlighted
Game
Verbs
Commands
Room
Player
Functions
Timers
Walkthrough
Advanced
Included Libraries
English.aslx
Core.aslx
Templates
Dynamic Templates
Object Types
Javascript
Filter -> Show Library Objects
2. at the top of the screen, in the menu bar, you want to click on "Add" (or whatever), and choose to add a "Turnscript"
Turnscript Name: global_turn_script // this is just my example (personal system~structure of) a name~label for it
// you'll probably want the Turnscript enabled at the start of the game (have the box checked), or if not... let me know, and I'll help you with setting it up to when~where you want it to be enabled, and obviously leave (or change it so that) the box UN-checked off.
in the Turnscript, you want to add this script:
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score = 10 // an example only
-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score = 20 // an example only
-> then, add a script -> // whatever script
Way~Method Two:
"game" Object -> Attributes (Tab) -> Attributes -> Add ->
// this is a special built-in Script Attribute name: changedAttribute_Name
// whenever your "game.score=number_amount" changes its Value (its number_amount), then its Script is run
Attribute Name: changedscore
Attribute Type: Script
Attribute Value: // see below
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score = 10 // an example only
-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score = 20 // an example only
-> then, add a script -> // whatever script
-------------
if you want to use "greater than" with your "score", then you'll need to add in this ("firsttime") to your scripting:
(I'm not sure what script category "firsttime" is under)
run as script -> add a script -> scripts -> if... -> [EXPRESSION] -> game.score >= 10 // an example only
-> then, add a script -> ?Scripts? -> Firsttime ->
->-> then, add a script -> Objects -> MoveObject -> // set it up
else if -> add a script -> Variables -> Set a variable or attribute -> game.score >= 20 // an example only
-> then, add a script -> ?Scripts? -> Firsttime ->
->-> then, add a script -> // whatever script
Liam315
06 Mar 2014, 11:31Quest has a built in function where you can create a script that runs whenever an attribute changes. So if you're using the default game.score attribute that HK described above, you would go to the attribute tab of the "game" object, scroll down to find score, click on it to highlight it and click on the button that says "create a change script". On the change script you can then add what you want to happen e.g.
Now every time the score increases, that script will run so if the score is 5, the object will be moved to the room.
if (game.score = 5) {
MoveObject(object,room)
}
Now every time the score increases, that script will run so if the score is 5, the object will be moved to the room.
michaelsahn
07 Mar 2014, 02:45It's working for me. Thanks again!
-Mike
-Mike