But there are two questions.
First of all, I want to figure out how SetVariable() works,however I can't find those code from renpy.
So,I changed my mind,I used Function() to complete the calculation I want.
But how can the value of Function() be fed back to screen?
There is my code(I'm a new fish, don't laugh at me )
Code: Select all
default flag001 = 0
default flag002 = 0
init -1 python:
import requests
import random
def plus_var_fun():
global flag001
flag001 = flag001 + random.randint(5,8)
if flag001 >= 50:
flag001 = 50
def red_var_fun():
global flag001
flag001 = flag001 - random.randint(5,8)
if flag001 <= 0:
flag001 = 0
label start:
$ flag001 = 21
$ flag002 = 5
scene black
call screen stats
return
screen stats():
use attack_fun(flag001,0.25)
use attack_fun(flag002,0.75)
screen attack_fun(hp, xalign):
frame:
xalign xalign
ycenter 0.25
xsize 180
ysize 320
vbox:
bar:
value AnimatedValue(value=hp, range=50, delay=0.3, old_value=None)
xsize 170
xcenter 0.5
if hp < 50:
textbutton "heal":
text_size 40
text_outlines[(absolute(2), "#effdff", absolute(0), absolute(0))]
text_color "#ed54de"
text_selected_color "#32e0fc"
action Function(plus_var_fun)
elif hp >= 50:
textbutton "backZero":
text_size 40
text_outlines[(absolute(2), "#effdff", absolute(0), absolute(0))]
text_color "#ed54de"
text_selected_color "#32e0fc"
action SetVariable("hp", 0)
if hp > 0:
textbutton "damage":
text_size 40
text_outlines[(absolute(2), "#effdff", absolute(0), absolute(0))]
text_color "#ed54de"
text_selected_color "#32e0fc"
action Function(red_var_fun)
elif hp <= 0:
textbutton "backFull":
text_size 40
text_outlines[(absolute(2), "#effdff", absolute(0), absolute(0))]
text_color "#ed54de"
text_selected_color "#32e0fc"
action SetVariable("hp", 50)
text "hp:[hp]"
I should design a function which have a parameter, but it's back to the beginning,how can the value of Function() be fed back correctly.
The second question is whether the code can be reused through such a design, but after the above code runs, an error will eventually be generate.
Renpy warns me : "The variable hp does not exist."
Do I need to define parameters like hp? I am confused.
Code: Select all
def plus_var_fun(x):
x = x + random.randint(5,8)
if x >= 50:
x = 50
def red_var_fun(x):
x = x - random.randint(5,8)
if x <= 0:
x = 0
besides, is it right on grammar "action Function(plus_var_fun, x=hp)"?
Godman please help me.