Not sure what to do with the shop command

I tried to make a shop command with the show menu thing. It only works so far if I use a random interger, or if I set a variable to a script. But neither works the way I want it to.

This is what the code is at the moment.
msg ("See something that catches your eye?")
ShowMenu ("Shop", split ("Potion;Hyper Potion" , ";"), true) {
result = GetRandomInt (1,2)
switch (result) {
case (1) {
player.gold = player.gold - 50
player.potion = player.potion + 1
}
case (2) {
player.gold = player.gold - 200
player.hyper_potion = player.hyper_potion + 1
}
}
}

Now it's just me getting a random integer, which obviously messes up what I was wanting to do.


to find out, "//" out the GetRandomInt
and add result=1
or result=2
and see what happens.


msg ("See something that catches your eye?")
ShowMenu ("Shop", split ("Potion;Hyper Potion" , ";"), true) {
  // result = YOUR_SELECTED_ITEM // result = "Potion" // or: result = "Hyper Potion"
  switch (result) {
    case ("Potion") { // if (result = "Potion")
      player.gold = player.gold - 50
      player.potion = player.potion + 1
    }
    case ("Hyper Potion") { // if (result = "Hyper Potion")
      player.gold = player.gold - 200
      player.hyper_potion = player.hyper_potion + 1
    }
  }
}

also, if you wan to use numbers:

msg ("See something that catches your eye?")
msg ("Shop")
stringlist_variable = split ("Potion;Hyper Potion", ";")
DisplayList (stringlist_variable, true) // or: DisplayList (stringlist_variable, false) // or: DisplayList (stringlist_variable, 0) // or: DisplayList (stringlist_variable, 1) // you probably want the list to be ordered/numbered (I just don't know from the doc, if you're to use 'true/false' or '0/1' for the second Argument/Parameter)
get input {
  // result = YOUR_TYPED_IN_INPUT // result = STRING_VALUE (even for number inputs)
  if (IsInt (result) and ToInt (result) > 0 and ToInt (result) <= ListCount (stringlist_variable)) {
    switch (result) {
      case ("1") { // if (result = "Potion")
        player.gold = player.gold - 50
        player.potion = player.potion + 1
      }
      case ("2") { // if (result = "Hyper Potion")
        player.gold = player.gold - 200
        player.hyper_potion = player.hyper_potion + 1
      }
    }
  } else {
    msg ("Wrong input, try again")
  }
}

you can also use a Dictionary Attribute, letting you convert number to item or vice versa... let me know if you're interested in this instead of using the 'DisplayList + get input'


ask if you got any questions... or need help with anything...


Phew. Got it. Thanks.


I have a new problem.
This is what I got.
msg ("See something that catches your eye?")
ShowMenu ("Shop", split ("Potion;Hyper Potion" , ";"), true) {
result = 1
result = 2
switch (result) {
case (1) {
if (player.gold > 50) {
player.gold = player.gold - 50
player.potion = player.potion + 1
msg ("You bought a Potion.")
}
else {
msg ("You have no gold.")
}
}
case (2) {
if (player.gold > 200) {
player.gold = player.gold - 200
player.hyper_potion = player.hyper_potion + 1
msg ("You bought a Hyper Potion.")
}
else {
msg ("You have no gold.")
}
}
}
}

The game thinks the result is always a Hyper Potion.


remove the:
ShowMenu ("Shop", split ("Potion;Hyper Potion" , ";"), true) {
result = 1 <---
result = 2 <---
switch (result) {
You are setting a value that overrides the get input function.

Also, change the:
msg ("You have no gold.")
to
msg("You are a little short on gold.")
or something like that...
I would be confused to be told I "have no gold" when I know I have 49 gold...


as Dark Lizard said:

quest automatically (it does this for you, hiddenly) sets/stores your: typed-in input (for 'get input' Script/Function) or your menu-selected input (for 'show menu / ShowMenu' Script/Function) into the built-in 'result' Variable VARIABLE:

result = YOUR_TYPED_IN_OR_MENU_SELECTED_INPUT

which you then over-write that Value with...

first: result = 1 // you replaced your input (typed in or menu selected: "Potion/Hyper Potion") with '1'

and then again (replaced it) to now being: result = 2 // you replaced your '1' with '2'

thus, it'll always do your: case (2)


see my previous post for the fixed-up code example of it


I have updated the documentation for ShowMenu, so hopefully it is clearer.

http://docs.textadventures.co.uk/quest/functions/showmenu.html


Fine. Thanks.


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

Support

Forums