Using imagebutton to return variables?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
tentacle
Newbie
Posts: 20
Joined: Thu Feb 24, 2011 6:37 am
Contact:

Using imagebutton to return variables?

#1 Post 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?

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Using imagebutton to return variables?

#2 Post by philat »

SetVariable("name", name-1) / SetVariable("name", name+1)

tentacle
Newbie
Posts: 20
Joined: Thu Feb 24, 2011 6:37 am
Contact:

Re: Using imagebutton to return variables?

#3 Post 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)

tentacle
Newbie
Posts: 20
Joined: Thu Feb 24, 2011 6:37 am
Contact:

Re: Using imagebutton to return variables?

#4 Post 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.

adrix89
Regular
Posts: 72
Joined: Fri Jun 26, 2009 12:15 pm
Contact:

Re: Using imagebutton to return variables?

#5 Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Imperf3kt, Semrush [Bot]