Hello everybody!
Twine 2.3.15
Sugarcube 2.34.1
Firefox 91.11.0esr (64 bits) and Edge 102.0.1245.30 (64 bits)
I’m trying to use arrays to store a lot of first names in order to generate first names randomly.
Example array (my problem is with all arrays).
StoryInit
<<set $NomF_al to ["Anett","Angela","Anna","Antonia","Astrid","Barbara","Beate","Birgit","Claudia","Charlotte","Christina","Denise","Elisabeth","Erika","Eva","Franziska","Frieda","Gabriele","Gisela","Heike","Helene","Helga","Ingrid","Jana","Jutta","Karin","Katarina","Katja","Kornelia","Kristin","Laura","Lena","Magdalena","Margitta","Maria","Marion","Marita","Nadine","Petra","Silke","Stefanie","Theresia","Ulrike","Ursula","Ute","Utta","Vanessa"]>>
At some point in the game I’m asking the reader what’s the culture of the tribe. The list is work in progress, I plan to add more cultures than already present.
Passage 1
Vous utilisez des noms <<listbox "$Peuple_culture">><<option "allemands" "allemande">><<option "français" "française" selected>><<option "grecs" "grecque">><<option "romains" "romaine">><<option "russes" "russe">><</listbox>>
Later I create two new arrays, the idea is to have a shortcut to the cultural names.
Passage 2
<<switch $Peuple_culture>><<case "allemande">><<set $NomF to $NomF_al>><<set $NomM to $NomM_al>><<case "française">><<set $NomF to $NomF_fr>><<set $NomM to $NomM_fr>><<case "grecque">><<set $NomF to $NomF_he>><<set $NomM to $NomM_he>><<case "romaine">><<set $NomF to $NomF_la>><<set $NomM to $NomM_la>><<case "russe">><<set $NomF to $NomF_ru>><<set $NomM to $NomM_ru>><</switch>>
Later I generate names with a widget.
Here’s the widget (I’m aware from 2.36 it should be _args, but I’m still using 2.34)
Formules
<<widget "Notable">><<nobr>><<switch $Peuple_place_sexes>><<case "un matriarcat" "un matriarcat dur">><<set _sexe to 2>><<case "un patriarcat" "un patriarcat dur">><<set _sexe to 1>><<case "favorable aux hommes">><<set _sexe to either(1,1,1,2)>><<case "favorable aux femmes">><<set _sexe to either(1,2,2,2)>><<default>><<set _sexe to either(1,2)>><</switch>>
<<if _sexe == 1>><<set _nom to $NomM.random()>><<else>><<set _nom to $NomF.random()>><</if>>
<<set _age to random($args[1],$args[2]) + random($args[1],$args[2]) + random($args[1],$args[2])>>
_nom est <<switch _sexe>><<case 1>>un homme âgé<<default>>une femme âgée<</switch>> de _age hivers. $args[0]
<<set $Peuple_notables.push([_nom,_sexe,_age,$args[0]])>><</nobr>><</widget>>
My problem is that, sometimes, the .random() returns [undefined]. It’s a trouble I’ve experimented with each array, so it’s not a trouble from one specific array. It means it’s probably not a comma or quote problem. Example:
Is there a commonly known problem I’m not aware of about <Array>.random()
, or maybe have I done something wrong?