Page 1 of 1

append with object name

Posted: Sat Apr 29, 2017 4:18 pm
by Mirrodin
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)

Re: append with object name

Posted: Tue May 02, 2017 3:10 pm
by renpic
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.

Re: append with object name

Posted: Tue May 02, 2017 3:30 pm
by Mirrodin
Thanks dude.

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