Shopping - adding money to total when taking money

demonboy
I'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?

Silver
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
}

HegemonKhan
here:

viewtopic.php?f=10&t=4946&start=15

ask if you need help

The Pixie
Silver 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
Apologies for the late reply. Thanks for these pointers, I shall implement them this weekend.

Cheers,

Jamie.

demonboy
OK, 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:


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
You misunderstood what I meant by add the first bit to 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
conceptually:

-------

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
Right, now I understand. Thanks, Silver, and to HegemonKhan for that example.

HegemonKhan
using 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:

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

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums