The money goes into the minuses

Ok, so I've got a sort of shop system going on, and it works. I'm happy with every aspect, except when the character tries to buy an item they can't afford, their money goes into the minuses. This is probably an over-asked question, but I can't find any articles on it. Please help (:


you need to use/add an 'if' Script , an example:

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] player.currency >= katana.price

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable player.currency = [EXPRESSION] player.currency - katana.price

// etc etc etc scripts (too lazy at the moment, let me know if you need help doing it with the GUI/Editor)

create ("katana")

katana.price = 5

player.currency = GetRandomInt (0,10)

----------

if (player.currency >= katana.price) {

  player.currency = player.currency - katana.price

  katana.parent = player

  msg ("You bought the katana")

} else {

  msg ("Sorry, but you can't afford the katana")

}

and/or:

max/min bounding:

create ("example_object")

example_object.minimum_currency = 0
example_object.maximum_currency = 1000000

--------

if (player.currency > example_object.maximum_currency) {

  player.currency = example_object.maximum_currency

} else if (player.currency < example_object.minimum_currency) {

  player.currency = example_object.minimum_currency

}

create ("test")

test.score = GetRandomInt (-100, 200)

create ("example_object")

example_object.maximum_score = 100
example_object.minimum_score = 0

-------

// min/max bound checking/correcting:

if (test.score > example_object.maximum_score) {

  test.score = example_object.maximum_score

} else if (test.score < example_object.minimum_score) {

  test.score = example_object.minimum_score

}

// high to low:

if (test.score >= 90) {

  test.grade = "A"

} else if (test.score >= 80) {

  test.grade = "B"

} else if (test.score >= 70) {

  test.grade = "C"

} else if (test.score >= 60) {

  test.grade = "D"

} else {

  test.grade = "F"

}

// high to low alternative (same as above but slightly more efficient due to less operations):

if (test.score > 89) {

  test.grade = "A"

} else if (test.score > 79) {

  test.grade = "B"

} else if (test.score > 69) {

  test.grade = "C"

} else if (test.score > 59) {

  test.grade = "D"

} else {

  test.grade = "F"

}

// low to high:

if (test.score < 60) {

  test.grade = "F"

} else if (test.score < 70) {

  test.grade = "D"

} else if (test.score < 80) {

  test.grade = "C"

} else if (test.score < 90) {

  test.grade = "B"

} else {

  test.grade = "A"

}

There is a tutorial on setting up a shop, which does cover this:
http://docs.textadventures.co.uk/quest/shop.html


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

Support

Forums