How to let Bar adjust python object? [solved]

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
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

How to let Bar adjust python object? [solved]

#1 Post by fluxus »

Hello - this one ought to be easy but somehow isn't.
I may be misunderstanding some Screen Language syntax.

Thing is, I have a nice object defined in script.rpy, and I'd like one of its attributes, a value, to be adjusted by a bar defined on a screen in screens.rpy.

So.
Defining object in script.rpy.
Calling screen with parameter containing, amongst other things, a number of said objects.
Iterating over the objects, doing things with each.
And one of the things to happen being to define a bar for each.

I try variations of

Code: Select all

vbar:
    value FieldValue(object=item, field="measure", range=item.size)
This doesn't seem to work, though.
I get a TypeError from an internal function apparently trying to subtract an 'instancemethod' from an 'int'.
Obviously I'm not using SL as intended :]


How am I supposed to do it?

I've used a ui.adjustment before, but that looks like deprecated code vs the new and shiny SL.

I might be able to get around this by defining screen variables and using those for the bar, but that is supposed to be done in an init -2 block, where I don't have my paramenter available and can't initialize the values correctly. Also then there'd be the transferring of screen variable values to script object values which sounds problematic if not impossible.
Last edited by fluxus on Fri Aug 22, 2014 9:20 am, edited 1 time in total.

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: How to let Bar adjust python object?

#2 Post by saguaro »

I always find bars a little tricky. This works for me---

Code: Select all

    bar:
        value FieldValue(object=item, field="measure", range=item.size,  max_is_zero=False, style='scrollbar', offset=0, step=0.1)
Apologies if I misunderstood, I wasn't able to replicate the error message you describe

User avatar
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

Re: How to let Bar adjust python object?

#3 Post by fluxus »

Ah thanks a lot.. sounds like I ended up on the right track after all.

It seems like my error isn't SL-related at all, actually. A short while ago, through judicious watches of everything, I found out that my supposedly simple float-on-an-object was actually a method object, just like the TypeError was trying to tell me.

Turns out I'd forgotten () at the end of a function call in another function which adjusted my supposedly simply float to new values.. thus assigning it the function and not what the function would otherwise have returned.

Score, Inner confusion: 1 :]

It's tricky when I'm not entirely certain of what I'm doing.. usually it's the screen language I'm messing up because I'm not very used to it.

If using FieldValue for a bar value is fine, then I should be able to figure this out. Will be reporting back :>

User avatar
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

Re: How to let Bar adjust python object?

#4 Post by fluxus »

Well, problem solved. I now have bars for each game object, adjusting things. Yay.
*marks topic as solved*

So, onwards to try to adjust one item according to the adjustments of another.
And somehow the 'changed' attribute doesn't seem to call the function specified.
*tampers*

Post Reply

Who is online

Users browsing this forum: Yone28