Shopping - adding money to total when taking money
demonboy
01 Mar 2015, 10:11I've been using the shopping library by the pixie but I'd like to add money to the total that the player carries when s/he picks up/examines a wallet. I can't get my head around the script I should run to add, say, €500 to the total when the wallet is either picked up or opened. On top of that I need to ensure that if the wallet is dropped and picked up again, another €500 is not added to the total.
Any clues?
Any clues?
Silver
01 Mar 2015, 10:52In your start script add:
Then on taking the wallet (or whatever) add this script:
wallet.taken = false
Then on taking the wallet (or whatever) add this script:
if (wallet.taken = true) {
msg("The wallet is empty")
} else { msg("You find £500 in the wallet and take it.")
// put the script that adds the money to the player object here
wallet.taken = true
}
HegemonKhan
01 Mar 2015, 11:00The Pixie
02 Mar 2015, 08:02Silver wrote:In your start script add:wallet.taken = false
Then on taking the wallet (or whatever) add this script:if (wallet.taken = true) {
msg("The wallet is empty")
} else { msg("You find £500 in the wallet and take it.")
// put the script that adds the money to the player object here
wallet.taken = true
}
The script that adds money should be:
player.money = player.money + 500
demonboy
06 Mar 2015, 01:08Apologies for the late reply. Thanks for these pointers, I shall implement them this weekend.
Cheers,
Jamie.
Cheers,
Jamie.
demonboy
07 Mar 2015, 05:09OK, I've implemented this and it adds the €500, which is great. Thanks for your help on that. However when I drop it and pick it up it adds another €500 to my total. Perhaps I missed the part in your explanation about how to prevent this but so far I have:
Any pointers?
After taking the object
wallet.taken = false
if (wallet.taken = true) {
msg ("The wallet is empty")
}
else {
msg ("You find £500 in the wallet and take it.")
player.money = player.money + 500
wallet.taken = true
}
Any pointers?
Silver
07 Mar 2015, 07:36You misunderstood what I meant by add the first bit to the start script.
remove this:
from that script. Where it is now it's telling the game that the wallet hasn't been picked up every time it's picked up.
What I meant originally is in order to use the boolean attribute in your game you have to tell the game about it. Click on 'game' and then there should be a tab called 'scripts' and then a section where you want scripts to happen as the game starts. You put it in there to tell the game that as the game begins wallet.taken hasn't happened (you're saying that attribute exists but it is currently false). You can also do this in the attributes tab but I just prefer to do it in the start script.
remove this:
wallet.taken = false
from that script. Where it is now it's telling the game that the wallet hasn't been picked up every time it's picked up.
What I meant originally is in order to use the boolean attribute in your game you have to tell the game about it. Click on 'game' and then there should be a tab called 'scripts' and then a section where you want scripts to happen as the game starts. You put it in there to tell the game that as the game begins wallet.taken hasn't happened (you're saying that attribute exists but it is currently false). You can also do this in the attributes tab but I just prefer to do it in the start script.
HegemonKhan
07 Mar 2015, 20:10conceptually:
-------
Initial Setting:
'game' Game Object -> 'scripts' tab -> 'start' Script -> (set it up; see below but its in pseudo-code):
light_switch_on_the_wall.is_the_light_switch_on?_boolean = false
------
Separate Action (the 'room' Object's 'light_switch_on_the_wall' Object's Verb called~named 'flip', for example):
-----------------
if you've got the initial setting as part of the Action, then it doesn't work, see if you can understand why on your own: a logic challenge for you, hehe.
-------
Initial Setting:
'game' Game Object -> 'scripts' tab -> 'start' Script -> (set it up; see below but its in pseudo-code):
light_switch_on_the_wall.is_the_light_switch_on?_boolean = false
------
Separate Action (the 'room' Object's 'light_switch_on_the_wall' Object's Verb called~named 'flip', for example):
'room' Object -> 'light_switch_on_the_wall' Object -> 'flip' Verb:
if (light_switch_on_the_wall.is_the_light_switch_on?_boolean = false) {
msg ("You flip the light switch on, the dark room becomes illuminated.")
light_switch_on_the_wall.is_the_light_switch_on?_boolean = true
} else if (light_switch_on_the_wall.is_the_light_switch_on?_boolean = true) {
msg ("You flip the light switch off, the illuminated room turns pitch black) {
light_switch_on_the_wall.is_the_light_switch_on?_boolean = false
}
-----------------
if you've got the initial setting as part of the Action, then it doesn't work, see if you can understand why on your own: a logic challenge for you, hehe.
demonboy
12 Mar 2015, 01:44Right, now I understand. Thanks, Silver, and to HegemonKhan for that example.
HegemonKhan
12 Mar 2015, 05:44using the computer's command line~prompt (start -> run -> cmd), as this is similiar to one of the simpliest~first languages: MS-DOS
quest's Scriptings (Commands, Functions, Turnscripts, Timers, Verbs ~ 'Script' Type Attributes, and etc) act in this same way: as the looping blocks
-------
we want code that will count up by 1, starting with 0, thus like this:
0 -> 1 -> 2 -> 3 -> 4 -> 5 -> etc etc etc
--------
Wrong structure:
:start
x = 0
x = x + 1
goto start // this loops back to the ':start'
output:
x = 0
x = 0 + 1 = 1
x = 0
x = 0 + 1 = 1
x = 0
x = 0 + 1 = 1
etc etc etc
the initial setting of 'x = 0' is inside of the looping block
-------------------------
Correct structure:
x = 0
:start
x = x + 1
goto start
output:
x = 0
x = 0 + 1 = 1
x = 1 + 1 = 2
x = 2 + 1 = 3
x = 3 + 1 = 4
etc etc etc
the initial setting of 'x = 0' is outside of the looping block
-----------
example in quest:
the 'foreach' is a built-in automatic looping function, as it is applying the scripts for each~all~every thing in the list
---------
let's say I want to create my own list displayment:
1. blah1
2. blah2
3. blah3
4. blah4
etc etc etc
--- this was before I knew about:
DisplayList ( http://docs.textadventures.co.uk/quest/ ... ylist.html )
DisplayList (Object_name.ListAttribute_name, true:ordered_or_false:disordered)
DisplayList (Object_name.ListAttribute_name, true)
~OR~
DisplayList (Object_name.ListAttribute_name, false)
lololol ... I wonder if the 'DisplayList:ordered' is achieved as I did did it, hmm... hehe
-----------
Wrong structure:
output:
1. red
1. blue
1. yellow
------------------------------
Correct structure:
output:
1. red
2. blue
3. yellow
quest's Scriptings (Commands, Functions, Turnscripts, Timers, Verbs ~ 'Script' Type Attributes, and etc) act in this same way: as the looping blocks
-------
we want code that will count up by 1, starting with 0, thus like this:
0 -> 1 -> 2 -> 3 -> 4 -> 5 -> etc etc etc
--------
Wrong structure:
:start
x = 0
x = x + 1
goto start // this loops back to the ':start'
output:
x = 0
x = 0 + 1 = 1
x = 0
x = 0 + 1 = 1
x = 0
x = 0 + 1 = 1
etc etc etc
the initial setting of 'x = 0' is inside of the looping block
-------------------------
Correct structure:
x = 0
:start
x = x + 1
goto start
output:
x = 0
x = 0 + 1 = 1
x = 1 + 1 = 2
x = 2 + 1 = 3
x = 3 + 1 = 4
etc etc etc
the initial setting of 'x = 0' is outside of the looping block
-----------
example in quest:
the 'foreach' is a built-in automatic looping function, as it is applying the scripts for each~all~every thing in the list
---------
let's say I want to create my own list displayment:
1. blah1
2. blah2
3. blah3
4. blah4
etc etc etc
--- this was before I knew about:
DisplayList ( http://docs.textadventures.co.uk/quest/ ... ylist.html )
DisplayList (Object_name.ListAttribute_name, true:ordered_or_false:disordered)
DisplayList (Object_name.ListAttribute_name, true)
~OR~
DisplayList (Object_name.ListAttribute_name, false)
lololol ... I wonder if the 'DisplayList:ordered' is achieved as I did did it, hmm... hehe
-----------
Wrong structure:
foreach (color_variable, split ("red;blue;yellow", ";")) {
x = 0
x = x + 1
msg (x + ". " + color_variable)
}
output:
1. red
1. blue
1. yellow
------------------------------
Correct structure:
x = 0
foreach (color_variable, split ("red;blue;yellow", ";")) {
x = x + 1
msg (x + ". " + color_variable)
}
output:
1. red
2. blue
3. yellow