Thank you very much for your help.
At first I reworked my game with setup object. Now all constants and functions are in setup.
Second thing about collections and generic object. It's not comfortable for me.( Sorry about this. I will try to make next game with this way, but now I use only numeric arrays. I use only intergers for my IDs (like ORC and it's very comfortable that I have list of all IDs in one place) and I hope that there will no problems.
Only question is: why setup.TIME_NAME[0] = "After sunset" and setup.STRENGTH[setup.ORC] = 10 so bad? I looked at manual about JS arrays, and it's correct syntax. Will I have problem with save and load because of this (if I use only integer IDs)? Or it's for beaty of code?
And last thing. I have something like this:
::StoryInit
<!-- ENEMIES -->
<<set setup.ORC = 0>>
<<set setup.ENEMY_NAME[setup.ORC] = "Orc">>
<!-- LOCATIONS -->
<<set setup.FOREST = 0>>
<<set setup.VILLAGE = 1>>
<<set setup.LOC_NAME[setup.FOREST] = "Forest">>
<<set setup.LOC_NAME[setup.VILLAGE] = "Village">>
<!-- EVENT IDS -->
<<set setup.TALK_WITH_ORC_ABOUT_LIFE_FOREST = 0>>
<<set setup.TALK_WITH_ORC_ABOUT_LIFE_VILLAGE = 1>>
<<set setup.FIGHT_WITH_ORC_FOREST = 2>>
<<set setup.FIGTH_WITH_ORC_VILLAGE = 3>>
<<set setup.TALK_WITH_ORC_ABOUT_WEAPON_FOREST = 4>>
<!-- EVENT TYPES -->
<<set setup.TALK = 0>>
<<set setup.FIGHT = 1>>
<!-- This clild/parent structure is necessary for generation. There are two events in <<set setup.EVENTS[setup.ORC][setup.FOREST][setup.TALK]>> = []>> but in real game it will be more in each array -->
<<set setup.EVENTS = []>>
<<set setup.EVENTS[setup.ORC] = []>>
<<set setup.EVENTS[setup.ORC][setup.FOREST] = []>>
<<set setup.EVENTS[setup.ORC][setup.VILLAGE] = []>>
<<set setup.EVENTS[setup.ORC][setup.FOREST][setup.TALK]>> = []>>
<<set setup.EVENTS[setup.ORC][setup.FOREST][setup.FIGHT]>> = []>>
<<set setup.EVENTS[setup.ORC][setup.VILLAGE][setup.TALK]>> = []>>
<<set setup.EVENTS[setup.ORC][setup.VILLAGE][setup.FIGHT]>> = []>>
<<set setup.EVENT_EXP = []>>
<<set setup.EVENT_TEXT = []>>
<<set setup.EVENTS[setup.ORC][setup.FOREST][setup.TALK].push(setup.TALK_WITH_ORC_ABOUT_LIFE_FOREST)>>
<<set setup.EVENT_EXP[setup.TALK_WITH_ORC_ABOUT_LIFE_FOREST] = 10>>
<<set setup.EVENT_TEXT[setup.TALK_WITH_ORC_ABOUT_LIFE_FOREST] = "You talk with orc in the forest about your life.">>
<<set setup.EVENTS[setup.ORC][setup.VILLAGE][setup.TALK].push(setup.TALK_WITH_ORC_ABOUT_LIFE_VILLAGE)>>
<<set setup.EVENT_EXP[setup.TALK_WITH_ORC_ABOUT_LIFE_VILLAGE] = 10>>
<<set setup.EVENT_TEXT[setup.TALK_WITH_ORC_ABOUT_LIFE_VILLAGE] = "You talk with orc in the village about your life.">>
<<set setup.EVENTS[setup.ORC][setup.FOREST][setup.FIGHT].push(setup.FIGHT_WITH_ORC_FOREST)>>
<<set setup.EVENT_EXP[setup.FIGHT_WITH_ORC_FOREST] = 20>>
<<set setup.EVENT_TEXT[setup.FIGHT_WITH_ORC_FOREST] = "You fight with orc in the forest.">>
<<set setup.EVENTS[setup.ORC][setup.VILLAGE][setup.FIGHT].push(setup.FIGHT_WITH_ORC_VILLAGE)>>
<<set setup.EVENT_EXP[setup.FIGHT_WITH_ORC_VILLAGE] = 20>>
<<set setup.EVENT_TEXT[setup.FIGHT_WITH_ORC_VILLAGE] = "You fight with orc in the village.">>
<<set setup.EVENTS[setup.ORC][setup.FOREST][setup.TALK].push(setup.TALK_WITH_ORC_ABOUT_WEAPON_FOREST)>>
<<set setup.EVENT_EXP[setup.TALK_WITH_ORC_ABOUT_WEAPON_FOREST] = 15>>
<<set setup.EVENT_TEXT[setup.TALK_WITH_ORC_ABOUT_WEAPON_FOREST] = "You talk with orc in the forest about weapon.">>
<<set $curloc = setup.FOREST>>
<<set $random_enemy = setup.ORC>> <!-- It will be generated -->
<<script>> <!-- It is very simplified. There are conditions for avalaible events -->
setup.throw_event = function(enemy, curloc, type) {
var events = [];
for (var event = 0; event < setup.EVENTS[enemy][curloc][type].length; event++) {
events.push(setup.EVENTS[enemy][curloc][type][event]);
}
return events.pluck();
}
<</script>>
::Main
You are in <<print setup.LOC_NAME[$curloc]>>
You see <<print setup.ENEMY_NAME[$random_enemy]>>.
<<link "Talk" "Talk">>
<<set $event = setup.throw_event($random_enemy, $curloc, $setup.TALK)>>
<</link>>
<<link "Fight" "Fight">>
<<set $event = setup.throw_event($random_enemy, $curloc, $setup.FIGHT)>>
<</link>>
<!-- These two passages I need cause it will be different choices after talk and fight -->
::Talk
<<print setup.EVENT_TEXT[$event]>>
<<set $exp += setup.EVENT_EXP[$event]>>
[[Next->Main]]
::Fight
<<print setup.EVENT_TEXT[$event]>>
<<set $exp += setup.EVENT_EXP[$event]>>
[[Next->Main]]
Is it normal that I place text in constants but not in passages? I mean all html file of game in RAM in any case so it's not difference for peformance? I will have many events and I heard that Twine will be slowed with more than 500 passages. And it's comfortable for me that all information (text and vars) about event in one place.