Hi, i'm pretty new to programming and i want to create a game where you can upgrade your wallet or health or whathaveyou.
So when you start the game you can only have 10 bucks with a minimum of 0, you then find a bigger wallet and now you can hold 20 bucks. (Hooray!)
I have already looked around the internet and i did find some stuff like this thread:
In that thread Saltome posts a line of code:
About a year ago i was dicking around with renpy as well and I remember I found the same thread and have gotten this little line of code to work. (I don't remember how)
Now though it completely crashes.
So if I understand correctly, I think it should work like this: first the lowest value wil be selected between the variable "energy" and 100 at "min(energy, 100)" then the highest value will be selected between the value decided by the min part and 0 within "max(min(), 0)" This should limit the value between 100 because min won't pass a higher value and 0 because max won't pass a lower value.
Now I think this code crashes because the 2nd energy part needs a value from the first energy part which isn't there and then stuff goes apeshit.
This is the code i used to test specifically this:
The screen is in a different .rpy file and goes like this:
Change the "max(min(Cash, MaxCash), 0)" to zero and the code works fine. But $Cash will go up and down indefinitely.
Can you guys help me get this code to work or do you maybe have a different solution?
I have tried the other bits of code in that thread but i couldn't get those to work either.
Thanks!
So when you start the game you can only have 10 bucks with a minimum of 0, you then find a bigger wallet and now you can hold 20 bucks. (Hooray!)
I have already looked around the internet and i did find some stuff like this thread:
You must be registered to see the links
In that thread Saltome posts a line of code:
Code:
$energy =max(min(energy, 100), 0)
Now though it completely crashes.
So if I understand correctly, I think it should work like this: first the lowest value wil be selected between the variable "energy" and 100 at "min(energy, 100)" then the highest value will be selected between the value decided by the min part and 0 within "max(min(), 0)" This should limit the value between 100 because min won't pass a higher value and 0 because max won't pass a lower value.
Now I think this code crashes because the 2nd energy part needs a value from the first energy part which isn't there and then stuff goes apeshit.
This is the code i used to test specifically this:
Code:
label start:
$MaxCash = 10
$Cash = max(min(Cash, MaxCash), 0)
show screen Cash
label lbl1:
menu:
"+1":
$ Cash += 1
jump lbl1
"-1":
$ Cash -= 1
jump lbl1
return
Code:
screen Cash:
text "Cash: [Cash]"
Can you guys help me get this code to work or do you maybe have a different solution?
I have tried the other bits of code in that thread but i couldn't get those to work either.
Thanks!