StaticValue(variable), variable is a value of variable

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
User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

StaticValue(variable), variable is a value of variable

#1 Post by Lezalith » Wed Dec 23, 2015 8:40 pm

So, I wrote on stackoverflow for this, but nobody has any idea what I'm talking about, so maybe LSF people will.

Code: Select all

label TeachingDone:
    python:
        if InTeaching == "Skill1":
            UsedSkill = "Skill1"
        elif InTeaching == "Skill2":
            UsedSkill = "Skill2Value"
        elif InTeaching ==  "Skill3":
            UsedSkill = "Skill3Value"
        else:
            pass
    call screen teaching_done
This is simple. Simple If, easy to understand, followed by screen.

Code: Select all

screen teaching_done:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
    bar:
        value StaticValue(UsedSkill, 10)            
        xalign 0.52
        yalign 0.8
        xmaximum 1000 
        ymaximum 30
        left_bar Frame("bar1.png", 10, 0) 
        right_bar Frame("bar2.png", 10, 0)
        thumb None


What interests us here is the StaticValue of the bar.
As we know, StaticValue(UsedSkill) will represent the value of variable called "UsedSkill". However, in the If we stated that UsedSkill's value is either Skill1Value or Skill2Value or SKill3Value, all of them being variables on their own and having integers as values.
I do not want bar to represent UsedSkill variable, I want it to represent variable that is stated as value of UsedSkill variable.

Someone suggested on the stackoverflow using dictionary, so I added it behind If:

Code: Select all

label TeachingDone:
    python:
        if InTeaching == "Skill1":
            UsedSkill = "1"
        elif InTeaching == "Skill2":
            UsedSkill = "2"
        elif InTeaching == "Skill3":
            UsedSkill = "3"
        else:
            pass
        dict = {1: 'Skill1Value', 2: 'Skill2Value', 3: 'Skill3Value'}
    call screen teaching_done
And changed the StaticValue:

Code: Select all

screen teaching_done:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
    bar:
        value StaticValue(dict[UsedSkill], 10)            
        xalign 0.52
        yalign 0.8
        xmaximum 1000 
        ymaximum 30
        left_bar Frame("bar1.png", 10, 0) 
        right_bar Frame("bar2.png", 10, 0)
        thumb None
This makes sense in my head (StaticValue searches through the dictionary, depending on value of UsedSkill StaticValue uses Skill1Value; Skill2Value or Skill3Value instead), BUT this gives me error on the line with bar:

I could go around this by making many screens with different bars, each for different value, and then showif them depending on the variables stated by If, but this would be painful as I plan to have more than 3 values and could result in performance issues (As all bars would be present with the showif).

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

Re: StaticValue(variable), variable is a value of variable

#2 Post by philat » Wed Dec 23, 2015 9:01 pm

Frankly, you're not making much sense. Are Skill1Value, etc., variables? Why are you assigning them as strings?

Code: Select all

screen test():
    bar:
        value UsedSkill
        range 10

default UsedSkill = 0
default Skill1 = 1
default Skill2 = 2

label start:
    show screen test()
    "0"
    $ UsedSkill = Skill1
    "1"
    $ UsedSkill = Skill2
    "2"
Will work perfectly. Try it yourself.

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: StaticValue(variable), variable is a value of variable

#3 Post by Lezalith » Wed Dec 23, 2015 9:51 pm

philat wrote:

Code: Select all

screen test():
    bar:
        value UsedSkill
        range 10

default UsedSkill = 0
default Skill1 = 1
default Skill2 = 2

label start:
    show screen test()
    "0"
    $ UsedSkill = Skill1
    "1"
    $ UsedSkill = Skill2
    "2"
Yes, this is what I want, but there are few problems.
Problem 1: Will this function the same way if I used AnimatedValue?
Problem 2: Skill1 and Skill2 will be different each time this screen is called, so I cannot state them as default.
Problem 3: This isn't working for me. If I go...

Code: Select all

screen teaching_done:
    default Skill2Value = 5
    bar:
        value UsedSkill   
        range 10
...while UsedSkill variable has value of "Skill2Value", the bar should be 50% full, right? Welp, it is 100% full for me, for some reason.

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

Re: StaticValue(variable), variable is a value of variable

#4 Post by philat » Wed Dec 23, 2015 11:21 pm

1. ...why wouldn't it?
2. Do you understand what 'default' does? It assigns a value if the variable doesn't exist -- you can absolutely modify those values. http://www.renpy.org/doc/html/python.ht ... -statement
3. See above. + Study how assignment works in python. UsedSkill = Skill2Value does not mean that if you change Skill2Value, UsedSkill will automatically reflect that change.

I don't really know what you're trying to do and how you're structuring it, and as such it's difficult to offer advice beyond what the immediate question is. I will say, however, that this idea of having a stand-in variable seems strange when you could pass the variable to the screen directly anyway...?

Code: Select all

screen test(var):
    bar:
        value var
        range 10

default skill1 = 1
default skill2 = 2

label start:
    show screen test(skill1)
    "skill 1"
    show screen test(skill2)
    "skill 2"

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: StaticValue(variable), variable is a value of variable

#5 Post by Lezalith » Thu Dec 24, 2015 8:06 am

philat wrote:3. See above. + Study how assignment works in python. UsedSkill = Skill2Value does not mean that if you change Skill2Value, UsedSkill will automatically reflect that change.
Yea, but isn't that basically what you did in the first reply? Bar reflecting value UsedSkill, stating Skill1 = 1, and saying UsedSkill = Skill1, "1". It made no sense to me, even though it's what I'm trying to do here, but that's basically what I got from that.

There is an option I could do many different screens with bars. Right now, I have...

Code: Select all

screen teaching_done:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
    bar:
        value UsedSkill   
        range 10
What I could do, is....

Code: Select all

screen teaching_done:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
    showif UsedSkill == Skill1:
            bar:
                value Skill1 
                range 10
    showif UsedSkill == Skill2:
            bar:
                value Skill2
                range 10
However, I am worried about performance issues, because Ren'Py documents say something about bars being still "called", even if the condition is met, and only rendered if it is.
ANOTHER WAY how I could do it without having to worry about performance is...

Code: Select all

screen teaching_done_1:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
            bar:
                value Skill1 
                range 10
screen teaching_done_2:
    tag mains
    add "TeachingDone.png" xalign 0.5 yalign 0.5
    text "{color=#e86b6b}[InTeaching]{/color}" xpos 900 ypos 35
            bar:
                value Skill2 
                range 10
... to create entire different screens and call only the one I need. Then again, I would need about 20 of those, because I intend on having about 20 skills.
So I wanted to make my life easier (Ironic, huh). In the second code in this reply, I am changing BARS. In the third code, I am changing entire SCREENS. What I wanted in the first code was to change only the VARIABLES inside of bar: value by having variable UsedSkill that would reflect which variable is supposed to be used.

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

Re: StaticValue(variable), variable is a value of variable

#6 Post by philat » Thu Dec 24, 2015 10:27 am

Look, this discussion in general would be much easier if you appeared to actually read my posts before responding to them -- whether you edit them later or not.

Pass the variable to the screen.


Edit:

I apologize if I'm being short. There are fundamental errors evident in your questions that make it very difficult to answer them.

That said, the most important error is that you don't appear to understand what exactly variables are or how assignment works.

http://foobarnbaz.com/2012/07/08/unders ... variables/

Code: Select all

UsedSkill = "Skill1" # attaches the name tag UsedSkill to the string "Skill1"
UsedSkill = Skill1 # attaches UsedSkill to whatever the value is of variable Skill1 (by default, it is 1 in the example code I post above)
if UsedSkill == Skill1: # compares value of variable UsedSkill to Skill1 -- by default in my example, it would compare 0 and 1 and come up false
if UsedSkill == "Skill1: # compares value of UsedSkill to string "Skill1"
By the examples you posted, I can guess at what you're trying to achieve, but I quite honestly don't see how you intend to achieve it specifically. In your first post, you use UsedSkill = "Skill1" and then try to put the value of UsedSkill (= still the string "Skill1", not a number) as the value of a bar. In your last post, you illustrate ShowIfs using if UsedSkill == Skill1, and given that I don't know the rest of the code, I don't know if that would end up comparing "Skill1" and some number, or different numbers, or what, but in any case, it is unlikely to produce the desired outcome.

As such, I would STRONGLY encourage you to 1) read the link above, and 2) pass the variable to the screen directly and bypass the need for this UsedSkill variable in the first place.

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: StaticValue(variable), variable is a value of variable

#7 Post by Lezalith » Thu Dec 24, 2015 11:24 am

I give up. I appreciate people trying to help, as this is not the only forum I've posted this problem to, but it seems that I just cannot explain what I want, even though it's so damn simple.
I'll just have to use another way and not brag about it being more time-consuming.

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_