I think a better title for this is "How to auto-generate instances of a class?", that's if I understood the problem correctly.
Basically you want to create many instances of this class? Is that what you want? Like...
Code: Select all
var1 = obj("name", "image", 0.5, 0.5)
var2 = obj("name", "image", 0.75, 0.5)
var3 = obj("name", "image", 0.45, 0.35)
...
If that's the case, then you actually going to change just one part of the code that I gave in order to achieve that and that's quite trivial. Just in case that if some part of the code is quite blurry to understand, I might as well explain the code that I did back there for you to understand it well.
Code: Select all
init python hide:
for i in range(10): # we are looping in this part, so the code below this block is expected to run 10 times because of range(10)
c = "c{}".format(i + 1) # the string name of the variable, such as c1, c2, c3 ~ c10
setattr(store, c, Character(c)) # we use setattr function to dynamically create a variable or attribute of the store
# setattr is called in this kind syntax: setattr(object, attribute_name, attribute_value)
# store is where all the variables that you create in renpy get stored, store is actually an object that got instantiated (e.g. store = StoreModule())
# attribute_name is a string name for the supposed to be created/set attribute of the object
# attribute_value is any object/value that we want to assign to the attribute of that object
As long as you know what the parameters are for the
setattr function, you wont get lost.
So to answer the question (If i understood it right), this is what you actually need to do (something like)...
Code: Select all
setattr(store, c, obj("name", "image", 0.5, 0.5))
And how do I assign different variables to each one? (Like giving each variable different xpos and ypos)
As for that, how do you plan to assign the xpos and ypos though? you mean like give them a random xpos and ypos? If yes, then you can use the
random module of renpy.
Code: Select all
rxpos = renpy.random.choice([0.0, 0.25, 0.5, 0.75, 1.0]) # randomly get a random xpos from the list
rypos = renpy.random.choice([0.35, 0.45, 0.55])
setattr(store, c, obj("name", "image", rxpos, rypos))