append with object name

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
Mirrodin
Regular
Posts: 104
Joined: Sun Mar 19, 2017 2:56 pm
Contact:

append with object name

#1 Post by Mirrodin » Sat Apr 29, 2017 4:18 pm

Hi.

I have a problem with syntax ... i guess
I want to add an object using the name of the variable and not the variable itself.
i need to do like in the exemple
objet_choisi.spellname equal "fireball"
And dosnt work because its just a string, not the "Competence" object.
How can i add the "Competence" Object with just its name ?

Code: Select all

$ fireball = Competence("sort","feu", "normal","boule de feu", "fire ball", "base", "base", 0,      0,      0,         30,         1.5,        10,        30,          0,      0)

$ fireball_book = Objet("For learn fireball ", "", "blabla", "eng", 500, "livre", "boule de feu",  0, "fireball", 0)

$ objet_choisi = fireball_book 

$ joueur.competences.append(objet_choisi.spellname)

renpic
Newbie
Posts: 19
Joined: Sat Apr 08, 2017 1:07 pm
Location: Europe
Contact:

Re: append with object name

#2 Post by renpic » Tue May 02, 2017 3:10 pm

Mirrodin wrote:How can i add the "Competence" Object with just its name ?

Code: Select all

$ joueur.competences.append(objet_choisi.spellname)
You can try with eval(object_choisi.spellname)... It isn't pretty, but it could work.

Otherwise, why don't you put an object reference inside the list of spells, along the name? You just have to add a field there, and perhaps your code would be cleaner.

User avatar
Mirrodin
Regular
Posts: 104
Joined: Sun Mar 19, 2017 2:56 pm
Contact:

Re: append with object name

#3 Post by Mirrodin » Tue May 02, 2017 3:30 pm

Thanks dude.

But i choose an other solution.
I finally create a list of all spell and pick in this for spell append.

Post Reply

Who is online

Users browsing this forum: Google [Bot]