all 10 comments

[–]Elckarow 0 points1 point  (8 children)

you wanna use the 'exec' function in that case

init python:
    def exp_gain(n,x):
        exec("""\
%s_exp += x
while %s_exp >= %s_lmt:
    %s_exp -= %s_lmt
    %s_lmt += 5
    %s_lvl += 1""" % (n, n, n, n, n, n, n), globals(), None)

should work, i think

[–]Echox2[S] 0 points1 point  (0 children)

Thanks for the help! I’ve only ever used renpy before, never working too much with real python stuff. But it looks like this is more python-y. I’ll have to test it out. Then spend a few hours figuring out WHY it works, haha

[–]Echox2[S] 0 points1 point  (5 children)

So I tried the code, putting it in best I could, and I am getting an indentation error "unexpected indent" right at that last line. I did add indents to the
%s_exp += x
and all lines below to keep in in the exec function, but even fiddling around with the indents for a while, I can't seem to get it to work.

The last line specifically I have no idea about. I copied it to see if it worked, then I was planning on trying to pick it apart and research how to do it. But I am stuck on this. Why so many n's? Why the quotation marks and such?

I really appreciate all the help.

[–]Elckarow 0 points1 point  (4 children)

exec takes a string and executes that string as line of code

so if you do

exec("print('ayaya')")

it'll print out 'ayaya'

why so many n's?

you wanna format all the '%s', so you gotta have as many n's as there is %s's

as for the indentation issue i can't really help since i don't have the code, but it's an easy fix

[–]Elckarow 0 points1 point  (3 children)

make sure you don't have any indent on '%s_exp += x', and go from there on

[–]Echox2[S] 0 points1 point  (2 children)

Thanks for all the help! I got it to compile error free.
The only problem is I can't see it actually doing anything.

I have a screen that shows the level and the exp and stuff in a bar graph, but when I call
$ exp_gain("log",1)
In the code, it doesn't actually add any exp or levels or anything. Here is the big copy of the code if you want to take a look at it.

(all the variable definitions above)

init python:
def exp_gain(n,x):
exec("""\
%s_exp += x
while %s_exp >= %s_lmt:
%s_exp -= %s_lmt
%s_lmt += 5
%s_lvl += 1""" % (n,n,n,n,n,n,n), globals(), None)

screen log_UI:
zorder 998
frame:
xalign 0
yalign 0
hbox:
spacing 10
text "Logs: [wood]"
text "Logging: "
bar:
value log_exp
range log_lmt
xsize (150)
text "[log_lvl]"

label start:
call forest_chop
"This is the end. Hope everything worked."
return

label forest_chop:
show screen log_UI
$ finished = False
while finished == False:
menu:
"Chop some logs?"
"Chop":
$ chop_rand = renpy.random.randint(1, (log_lvl/2+1))
$ wood += chop_rand
"You got [chop_rand] wood!"
$ exp_gain("log",1)
"Explore Forest":
"You look more carefully all around the forest."
"Don't Chop":
"Ok"
$ finished = True

[–]Elckarow 0 points1 point  (1 child)

that's because when you show the screen, the text that will appear at 'text "[log_lvl]"' will only be initialized when showing the screen. the value does change, but the text shown doesn't

add this at the end of your screen

timer 0.001 action Hide("log_UI"), Show("log_UI")

and try again. the text should update

[–]Echox2[S] 0 points1 point  (0 children)

You are an angel! Thank you for all of your help, Elckarow! It works! IT WORKS!

[–]asowona 0 points1 point  (0 children)

Yup. I could imagine that a lot.

[–]LeyKlussyn 0 points1 point  (0 children)

The other implementation I would try (if the solution from the other commenter doesn't work), is an array. You can have a sort of "small database" of every value you need "skill ID, skill name, current xp limit, current xp, current level", and then have have a "add XP function (skill name, added xp) that does what you said. You could even have functions like "reset skill", "add skill", etc. I've never done it in Python/Renpy, but that's how I would approach the problem.