Page 1 of 1

Using imagebutton to return variables?

Posted: Sat May 08, 2021 3:17 am
by tentacle
I'm trying to make a character creation feature, where you have X points to allocate, you click icons corresponding to str, int, etc, and when clicked, subtract a point and add one to whatevever attribute that was clicked.

Here's a simplified example:

Code: Select all

screen chargen
  imagebutton auto "str_%s.png":
    xpos 200 ypos 200
    action Return("str"), Jump("buttonclicked")

Code: Select all

$ points = 10    
$ str = 3

label chargen:
  show screen chargen
  while points > 0:
    "you have [points] points left to allocate"
  jump character_creation_done

label buttonclicked:
  $ XXXX += 1         
  "added 1 to XXXX"
  $ points -= 1
  jump chargen
But how to specify the XXXX to be whatever was clicked...? Or is this completely the wrong approach?

Re: Using imagebutton to return variables?

Posted: Sat May 08, 2021 3:27 am
by philat
SetVariable("name", name-1) / SetVariable("name", name+1)

Re: Using imagebutton to return variables?

Posted: Sat May 08, 2021 6:01 am
by tentacle
Thanks, I knew I was on the wrong track!

It works with a simple variable, but is it possible with an array as well, e.g. if player[0] is strength? I don't find any examples/docs.

This (and other formats I tried) just give an exception:
action SetVariable("player[0]", player[0]+1)

Re: Using imagebutton to return variables?

Posted: Sat May 08, 2021 3:38 pm
by tentacle
I've worked around this by just making variables like player.strength instead of arrays.
It's uglier but I can live with it.

Re: Using imagebutton to return variables?

Posted: Sat May 08, 2021 4:26 pm
by adrix89
tentacle wrote:
Sat May 08, 2021 6:01 am
Thanks, I knew I was on the wrong track!

It works with a simple variable, but is it possible with an array as well, e.g. if player[0] is strength? I don't find any examples/docs.

This (and other formats I tried) just give an exception:
action SetVariable("player[0]", player[0]+1)
Call your own function and use the store.player, the SetVariable functions pretty much do the same thing with the store I believe.