What do these scripts do?

Espera
24 May 2014, 03:12
When I go to the 'Scripts' subsection of the Scripts list in the UI, I get quite a selection of options, and I only know what a few of them do. I figure if I could master these, they could be valuable tools in my toolbox. More than knowing ust how these options are used, I'm interested in knowing why, or when, they should be used. The ones I'm interested in right now are "For..." "For each..." and 'Siwtch". Can someone tell me about these?

HegemonKhan
24 May 2014, 05:15
this probably won't help you, as I'll be going over this stuff using code, but I hope it'll at least make some sense to you a bit with conception-understanding at least (I hope, HK crosses his fingers, lol)...

(hopefully you can figure out how to do this stuff via the GUI~Editor, as I'm just not that familar with it yet, and it takes so much longer to try to explain stuff using the GUI~Editor, sighs)

(unfortunately, what, how, when, why, where, and etc to use different code designs... takes years of experience... I'm struggling with this myself... I make really messy code~scripts, and then Jay, Pertex, Pixie, Chase, Sora, and etc... come along and do the same stuff in like only a 1/10 of the amount of code, is super neat ~ easy to understand, and etc... argh... lol! And I never even realized to do it that way that they do it... it's a lot like math... it's like me and you can only use addition, whereas experienced coders can use everything: from addition to calculus and beyond... they know what's the best math ability to use to solve something, whereas me and you are stuck with just using addition... we don't even know that multiplication, algebra, trig, calculus, and etc exists, let alone when, where, why, and how, to use which one of them for which situation-problem, lol. It's like I need to do a 100 step proof to solve a math problem, but they can solve the math problem in just a 10 step proof!)

-----------

01. http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
02. http://quest5.net/w/index.php?title=Cat ... t#mw-pages (page 2, range: S-Z)
03. http://quest5.net/wiki/GetRandomInt
04. http://quest5.net/wiki/ListCount
05. http://quest5.net/wiki/Using_Lists
06. http://quest5.net/wiki/Using_Dictionaries (this is a bit more complicated than using lists)
07. http://quest5.net/wiki/Split
08. http://quest5.net/wiki/Join (this isn't really used much by non-advanced coders, I don't even understand why~when you'd ever use this function, lol)
09. http://quest5.net/wiki/Foreach
10. http://quest5.net/wiki/For
11. http://quest5.net/wiki/NewStringList
12. http://quest5.net/wiki/Category:Scopes
13. http://quest5.net/wiki/Stringlist
14. http://quest5.net/wiki/Objectlist
15. http://quest5.net/wiki/List_add
16. etc... lol

---------------------

'for' and 'foreach' deals with Lists (stringlists and objectlists).

before I talk about 'for' and 'foreach', first we must get into what lists are:

(1) red, (2) blue, or (3) yellow

lists provide a selection of choices (a collection of strings, separated as individual selections to choose from), in the above example: red, blue, or yellow

String: redblueyellow
StringList: (1) red, (2) blue, or (3) yellow

String -> 'splits' into a -> StringList
StringList -> 'joins' into a -> String

the 'split' function creates a StringList (or ObjectList)

Object.StringList = split ("item_1;item_2;item_3;etc", "separator_character")

conceptually:

game.primary_colors_string_list = split ("string: redblueyellow", "separator_character: semicolon")
game.primary_colors_string_list = split ("red;blue;yellow", ";")

game.primary_colors_string_list = split ("string: redblueyellow", "separator_character: plus sign")
game.primary_colors_string_list = split ("red+blue+yellow", "+")

game.primary_colors_string_list = split ("string: redblueyellow", "separator_characters: HK")
game.primary_colors_string_list = split ("redHKblueHKyellow", "HK")

usually people use the semicolon as the separator character (using the 'split' in a 'show menu', as an example):

show menu ("What is your race?", split ("human;dwarf;elf", ";"), false) {
-> player.race_string = result
}

and, you can also make Lists this way too:

Object.StringList = NewStringList ()
list add (Object.StringList, "item_1")
list add (Object.StringList, "item_2")
list add (Object.StringList, "item_3")
// etc

so, that's what Lists are, but now for what is useful about those lists:

as I already shown, you can use them for a choice of selections to make

however, the other useful thing with lists is that you can use them to act upon specific items within the list (via 'for') or to act upon ALL~EVERY~EACH item within the list (via 'foreach'):

though for you to understand how this works, I got to explain something about lists:

while 'split ("red;blue;yellow", ";")' has three items (red-1, blue-2, yellow-3), their actual list ordering begins with ZERO:

list item order ('indexing'):
0: red
1: blue
2: yellow

so (using my above example)...

StringListItem (game.primary_colors_string_list, 1) -> outputs~returns: blue
StringListItem (game.primary_colors_string_list, 2) -> outputs~returns: yellow
StringListItem (game.primary_colors_string_list, 0) -> outputs~returns: red
StringListItem (game.primary_colors_string_list, 3) -> outputs~returns: ERROR~null, there is no 4th item (no item ordering of 3)

this allows for some cool stuff, such as random selection:

GetRandomInt (min, max)

game.primary_color_choosen_string = StringListItem (game.primary_colors_string_list, GetRandomInt (0,2))
game.primary_color_choosen_string = // (a random choice of either red; blue; or yellow)

and also this is extremely useful too with lists:

ListCount (game.primary_colors_string_list) -> outputs~returns: 3 (# of items in the list, NOT the list ordering, ya it gets some getting used to, very confusing for quite awhile)

game.primary_color_choosen_string = StringListItem (game.primary_colors_string_list, GetRandomInt (0,ListCount (game.primary_colors_string_list)) -> outputs~returns: // (a random choice of either red; blue; or yellow)

list remove (game.primary_colors_string_list, "yellow")

game.primary_color_choosen_string = StringListItem (game.primary_colors_string_list, GetRandomInt (0,ListCount (game.primary_colors_string_list) - 1) -> outputs~returns: // (a random choice of either red or blue)

* the 'ListCount (Object.List) - 1' is because of the difference between number of items in a list and the list's ordering:

ordering: color_string (number of items)
0: red (1st item)
1: blue (2nd item)
2: yellow (3rd item)

ListCount = 3
3 - 1
List item ordering: 2

StringListItem (Object.List, GetRandomInt (0, ListItem (Object.List) -1))
StringListItem (Object.List, GetRandomInt (0, 3 -1))
StringListItem (Object.List, GetRandomInt (0, 2))
// outputs~returns: (either: red, blue, or yellow)

if you don't do the 'ListCount (Object.List) - 1', you get problems~errors:

StringListItem (Object.List, GetRandomInt (0, ListItem (Object.List)))
StringListItem (Object.List, GetRandomInt (0, 3))
// outputs~returns: (either: red, blue, yellow, or... ???... no 4th item... ERROR~null...BIG PROBLEMS!)

-------

the importance of this, is that it finds the number of items in the list currently, without your intervention of 'coding' (typing) in the right number into the code line, which is not always possible for you to do, when you got code of changing list items taking place.

---------

alright, I've explained a bit more than what you asked for in the above, so let me now get to explaining what you wanted: 'for' and 'foreach', though I think the above helps with understanding this stuff too (if it doesn't confuse you even more, argh, lol):

so you got a string list:

game.primary_colors_string_list = split ("red;blue;yellow", ";")

if I want to do the same action(s) for ALL~EVERY~EACH item within the string list:

http://quest5.net/wiki/Foreach

item_x -> 1st as: red
item_x -> 2nd as: blue
item_x -> 3rd as: yellow
// etc

foreach (item_x, game.primary_colors_string_list)
-> msg ("Color: " + item_x)
}
// outputs~returns #1: Color: red
// outputs~returns #2: Color: blue
// outputs~returns #3: Color: yellow

let's use the example of an object list now:

game.fruit_string_list = split ("apple;orange;lemon", ";")

foreach (item_x, game.fruit_string_list)
-> MoveObject (item_x, player) // or (this does the exact same thing as 'MoveObject'): item_x.parent = player
}
// the "player" Player Object now holds these items: apple, orange, and lemon

or, we can do a Verb script too:

Verb: "eat"; the 'apple', 'orange', and 'lemon' Objects have all be given (add verb) the "eat" verb

foreach (item_x, game.fruit_string_list)
-> invoke (item_x.eat)
}
// you do the apple's eat verb
// you do the orange's eat verb
// you do the lemon's eat verb

or here's a good analogy example for you:

game.team_string_list = split ("team_member_1;team_member_2;team_member_3", ";")

foreach (team_member, game.team_string_list)
-> invoke (team_member.run_laps)
}
// ALL~EVERY~EACH team member runs laps

now, about 'for':

http://quest5.net/wiki/For

(iterator variable, int from, int to) { script }
or
(iterator variable, int from, int to, int step) { script }

remember, list ordering starts at ZERO:
0: team member 1
1: team member 2
2: team member 3

for (team_member, 0,2)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 2 runs laps
// team member 3 runs laps

for (team_member, 0,1)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 2 runs laps

for (team_member, 1,2)
-> invoke (team_member.run_laps)
}
// team member 2 runs laps
// team member 3 runs laps

for (team_member, 0,0)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps

for (team_member, 1,1)
-> invoke (team_member.run_laps)
}
// team member 2 runs laps

for (team_member, 2,2)
-> invoke (team_member.run_laps)
}
// team member 3 runs laps

for (team_member, 0,2,2)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 3 runs laps

for (team_member, 0,2,1)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 2 runs laps
// team member 3 runs laps

(let's add more team members to show more examples):

5 team members:
(remember, list ordering starts at ZERO)
0: team member 1
1: team member 2
2: team member 3
3: team member 4
4: team member 5

for (team_member, 0,4,2)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 3 runs laps
// team member 5 runs laps

for (team_member, 0,4,4)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 5 runs laps

for (team_member, 0,4,3)
-> invoke (team_member.run_laps)
}
// team member 1 runs laps
// team member 4 runs laps

--------

and don't forget you can use randomness: GetRandomInt (min, max), and also the current number of items too: ListCount (Object.List) - 1

-------

basically, lists enable you to group many (strings or objects: string lists or object lists), so that you can then do actions upon either: all~every~each of that group of strings~objects (via 'foreach'), or on a specific range (ie specific) of those string~objects within that group (via 'for').

also, lists enable you to easily adjust-change them (adding or removing items, ie: string or object), as well.

for example, let's say you got a random dialogue script block, such as when talking to an NPC (a non-playable-character, ie a 'townsfolk' vs a 'monster'), but you don't want the same dialogue choice being randomly selected over and over again, each time a dialogue msg script is selected, it is removed from the list, and the next time you talk to the NPC, it randomly selects from that now smaller list of choices, and again and again, until all the dialogue msgs are selected and seen by the person playing the game.

or, like in many games, you want to have 'events' from 'exploring', or from opening a chest that can be reopened for new items.

or for example, with a 'travel' or 'goto' or 'warp' feature~spell~whatever.

I can provide game code, for you to play out and study, of an 'explore' and 'travel' features, which is a real example of lists, (dictionaries too ~ which are a bit more complicated then lists ~ once you understand lists, let me know, and I'll try to help you with understanding dictionaries), 'for', 'foreach' and etc stuff ('GetRandomInt', 'ListCount', 'StringListItem', 'Object'ListItem'), so just let me know if interested in it.

HegemonKhan
24 May 2014, 05:58
continued... (about 'switch')

-----------

1. http://quest5.net/wiki/Tutorial
2. http://quest5.net/wiki/Multiple_choices ... %22_script
3. http://quest5.net/wiki/How_to
4. http://quest5.net/wiki/Switch
5. http://quest5.net/wiki/Hs-case ('switch')

the 'switch' function is just a different format~design of doing multiple ('nested'~indented) 'if' scripts:

(depends on the situation, sometimes using 'if' scripts is better, sometimes using 'switch' scripts is better, sometimes using both 'if' and 'switch' is better, sometimes using dictionaries is better... hehe, and sometimes using... ??? ~ advanced code ability that I'm not at yet, is better, lol)

if (player.alias = "HK") {
-> // player.gender_string = "male"
-> if (player.gender_string = "male") {
->-> player.strength_integer = player.strength_integer + 1
-> } else if (player.gender_string = "female") {
->-> player.intelligence_integer = player.intelligence_integer + 1
-> }
} else if (player.alias = "espera") {
-> // just for an example: player.gender_string = "female"
-> if (player.gender_string = "male") {
->-> player.strength_integer = player.strength_integer + 1
-> } else if (player.gender_string = "female") {
->-> player.intelligence_integer = player.intelligence_integer + 1
-> }
}

is the exact same as (using 2 layers~levels~'nesting'~indenting of 'switch', but you can also do the first layer as 'switch' and the second layer as 'ifs' too, or vice-versa, or any combination of 'switch' and 'ifs' ~ if you have a larger script block, but I'm not going to show 'switch'+'ifs', as I'm too tired now, lol):

switch (player.alias) {
-> case ("HK") {
->-> // player.gender-string = "male"
->-> switch (player.gender_string) {
->->-> case ("male") {
->->->-> player.strength_integer = player.strength_integer + 1
->->-> }
->->-> case ("female") {
->->->-> player.intelligence_integer = player.intelligence_integer + 1
->->-> }
->-> }
-> }
-> case ("espera") {
->-> // just for an example: player.gender_string = "female"
->-> switch (player.gender_string) {
->->-> case ("male") {
->->->-> player.strength_integer = player.strength_integer + 1
->->-> }
->->-> case ("female") {
->->->-> player.intelligence_integer = player.intelligence_integer + 1
->->-> }
->-> }
-> }
}

-------------

for the 'for' and 'foreach', you can look at the libraries ( viewforum.php?f=18 ), such as chase's wearables (equipment) library:

viewtopic.php?f=18&t=2901

you can see an implementation of the 'foreach'~'for' in action.

-----------

this is a good thread too:

viewtopic.php?f=10&t=4279&hilit=HK+travel+code

and here's my 'explore' and 'travel' code for you to play with and study (though it's quest v540, so if you're using quest v550, you'll not be able to use~play my game code, unless you can get it converted to v550):

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
<start type="script">
msg ("Important Note:")
msg ("Type in: help")
</start>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>

Espera
25 May 2014, 00:46
I already know a lot about lists, so some of that was wasted effort, but luckily not entirely. It did show me a couple shortcuts I hadn't thought of using. Also, you might have unintentionally solved a conundrum for me which was how to deal with a deck of cards.

I tink I'm starting to get what you're talking about when it comes to the three scripts I asked about. If I'm lucky, maybe Switch can help me a bit with my combat system.

HegemonKhan
25 May 2014, 02:35
what are you trying to do with your combat system? if you don't mind talking about what you want to do, I'd be glad to help you with it, as I too am interested in combat systems. what aspect of the combat system do you want to use 'switch' with?

show menu ("What are you going to do?", split ("attack;defend;cast;item;run", ";"), false) {
-> switch (result) {
->-> case ("attack") {
->->-> // blah scripts~code lines
->-> }
etc etc etc

or did you want to use 'switch' with equipment or spells~magic, within combat? or something else?

and sorry about the stuff about lists, didn't know what you already knew about, hehe.

Espera
25 May 2014, 05:50
My combat system for my first game that employs one is a bit simple, and maybe strange, but it works. Sadly, it's a bit of a slugfest, consdiering I haven't implimented a 'chance to hit' system yet, or likely will in this game, though I know how I'd do it now.

I don't have a defined 'combat mode'. The player can just choose to 'fight' some objects (monsters, other sorts of antagonists), and this calls up their movelist, which expands over the game with differetn moves. Equipping a new weapon might grant a new move, or reading a spellbook might, etc.

Because combat in the game revolves around verbs associated with each antagonist, the effects of the moves can be customized in their effects for each adversary quite easily. Also, it eliminates the need for options like 'item' or 'run', as you can use all other commands normally, like accessing your inventory, or using the exit you came in through.

Enemies attack using turn scripts actived either when the player enters the room or aggresses the adversary. This means the player can look at or even talk to some enemies before fighting them.

It's a bit cumbersome and simplistic, but it works for now.

HegemonKhan
25 May 2014, 15:55
that's awesome. how did you want to employ 'switch', 'for', and 'foreach' into combat? Did you have anything in mind, or just wanted to understand better how they work and~or what they can be used to do? (really, 'switch' is just an alternative to using 'ifs', and while it's design-look-format is more organized~neat~clean for our eyes, 'switch' is not as powerful~useful as 'ifs', you're more limited with 'switch' than 'ifs', but it's easier on the eyes)

as far as I know in coding, lists and their 'for' and 'foreach' is for making a group of items (strings or objects), which you can add or remove from the group, and reference~call~use either all of the items or a select range of specific items for acting upon with an action. You can use two lists for 'string matching' involved actions, a very powerful coding technique to do lots of cool stuff. Also, you can use them with randomization, a 'treasure class' (hopefully you're familiar with this term, lol) system for item drops, events, dialogue, and etc. There's many more uses too, but I'm only a beginner with coding, hehe.

now, if you're interested in moving onto dictionaries, you can do a lot of more cool things with them, and along with lists too, you can do really cool things.

see my link in my previous post, which takes you to the 'enemies movement thread', as I try to explain dictionaries in my posts in there.

-----------------

one more thing about lists' usage, that I just thought of:

Lists also are a much better alternative than using cumbersome booleans, and it allows for more easily using~doing multiple booleans~'effects' at the same time, for example:

instead of having tons of boolean attributes, such as for example of 'status effects':

player.poisoned = false
player.asleep = false
player.confused = false
player.stunned = false
player.paralyzed = false
player.petrified = false
player.silenced = false
player.blinded = false
player.cursed = false
player.blessed = false
etc etc etc

(or for example 'locomotion~movement~etc actions':

player.bipedal (two-legged) = false
player.quadripedal (four-legged) = false

player.walking = false
player.running = false
player.jumping = false
player.falling = false
player.floating = false
player.swimming = false
player.flying = false
player.climbing = false
player.crawling = false
player.standing = false
player.sitting = false
player.laying_down = false

player.stealing = false
player.sneaking = false
player.lockpicking = false

player.defending = false
player.escaping = false
player.casting = false

player.sleeping = false
player.resting = false
player.playing = false
player.working = false
player.studying = false
player.reading = false
player.watching = false

etc etc etc)

I can instead use a list:

player.status_effects_string_list = NewStringList ()

list add (player.status_effects_string_list, "poisoned")
list add (player.status_effects_string_list, "silenced")
list remove (player.status_effects_string_list, "poisoned")
list add (player.status_effects_string_list, "stunned")
list add (player.status_effects_string_list, "cursed")

so, I can then simply check this list for what are my status_effects, much better than constantly turning on~off tons of booleans.

(I don't know the correct syntax off-hand)
if (ListContains (player.status_effects_string_list, "cursed") = true) {
-> // some script(s)
}
if (ListContains (player.status_effects_string_list, "poisoned") = true) {
-> // some script(s)
}

~OR~

(two lists~dictionaries, using 'string matching', for this example, a string list and a script dictionary)

conception:
script dictionary: string = script
script dictionary: string -> script
script dictionary: if (string), then do~return~output: script

script dictionary: if ("attack") { orc.current_hit_point_integer = orc.current_hit_point_integer - player.damage_integer }
script dictionary: if ("defend") { player.current_defense_integer = player.current_defense_integer * 2 }

foreach (item_x, player.status_effects_string_list) {
-> foreach (item_xx, game.all_status_effects_script_dictionary) {
->-> if (item_x = item_xx) {
->->-> invoke (ScriptDictionaryItem (game.all_status_effects_script_dictionary, item_x))
->-> }
-> }
}

you can use lists and string dictionaries, for doing casting, such as the 'affinities', for example: 'weakness', 'normal', and 'immunity' (but there's also: 'strong', 'reflection', and 'absorption' too):

conception:

string dictionary: string1 = string2
string dictionary: string1 -> string2

if (string1), then return~output~('conversion'): string2

string dictionary: water=fire; fire=water; earth=air; air=earth

if (water), then return~output~(convert to): fire
if (fire), then return~output~(convert to): water
if (earth), then return~output~(convert to): air
if (air), then return~output~(convert to): earth

if ice~water monster, then your fire spell does double damage

frost_giant.elemental_string = "water"
your_fireball_spell.elemental_string = "fire"

if (your_fireball_spell.elemental_string = StringDictionaryItem (frost_giant.elemental_string) {
-> orc.current_hit_point_integer = orc.current_hit_point_integer - (your_fireball_spell.damage_integer * 2)
-> msg ("You do double damage as the frost giant is weak to your fire elemental spell")
} else if (your_fireball_spell.elemental_string = frost_giant.elemental_string) {
-> msg ("You do no damage to the frost giant, as it is immune to ice~water elemental spells")
} else {
-> orc.current_hit_point_integer = orc.current_hit_point_integer - your_fireball_spell.damage_integer
-> msg ("You do normal damage with your spell, as it is neither fire nor water~ice elemental")
}

how it works:

if (your_fireball_spell.elemental_string = StringDictionaryItem (frost_giant.elemental_string) {
if (fire = StringDictionaryItem (water) {
if (fire = conversion_functionality_of_StringDictionaryItem (water->fire) {
if (fire = fire) {, you do double damage

as we can't go: if (fire=water) {, do double damage, lol: 'f-i-r-e' is NOT equal to 'w-a-t-e-r', so no double damage
nor can we do: if (fire = not fire) {, do double damage, lol: we don't want earth and air doing double damage to our frost giant.

Credit entirely goes to Pixie (via his~her Spell Library), for this ingenius code design method (it took me a long time to grasp it, argh, but I understand it now, hehe) :D

Espera
28 May 2014, 06:09
I don't have any specific plans for those scripts yet. I'm just trying to increase my knowledge of my options, and so far, it isn't working particularly well. What I mostly got out of what you told me is maybe I could use 'For each...' for something like a 'Tall all items' option, but that isn't a priority for me now. It seems like maybe 'For... ' could do fine for when the player is fighting groups, and so they each get an action? I could only hope that would be something more efficient than just giving each of them a turn script.

Dictionaries seem like they are pretty important to grasp, but at the moment, I still don't quite get them. I can sort of grasp using the conversion tool, but it seems so limited. I'm obviously missing some things.

HegemonKhan
28 May 2014, 06:19
as it's hard (at least for me anyways) to explain what different coding designs can all various things that they can do for you...

maybe it would work better, if you don't mind, telling your ideas for your game, since you don't know of the code design methods, tell us what you want to do, and then we can give different options for~of code design methods (well, I'll try to, as I'm too trying to build up my knowledge of code design methods too, hehe) for you to do what you want.

--------------

dictionaries are extremely useful, due to the 'conversion', and thus doing 'string matching', though this is a difficult thing to grasp (look at, study, Pixie's Spell Library, and see if you can understand how the opposite elements work).

just a quick note about dictionaries: they do *NOT* have ordering~indexing, you can only reference their key's by string label, unlike lists where you can use the numbers of their ordering~indexing. Aside, from their 'conversion-effect', Dictionaries are just like the 'switch' function (which is just an alternative of using multiple 'if' scripts):

switch (Object.gender_string_list) {
-> case ("male") {
->-> // script1
-> }
-> case ("female") {
->-> // script2
-> }

ScriptDictionaryItem (Object.gender_string_list, "male") -> returns~outputs: // script1

<attr name="gender_string_script_dictionary" type="scriptdictionary">
-> <item key="male">
->-> // script1
-> </key>
-> <item key="female">
->-> // script2
-> </key>
</attr>

-------------

show menu ("What is gender?", split ("male;female",";"), false) {
-> switch (result) {
->-> case ("male") {
->->-> // script1
->-> }
->-> case ("female") {
->->-> // script2
->-> }
-> }
}

msg ("What is your gender?")
get input {
-> switch (result) {
->-> case ("male") {
->->-> // script1
->-> }
->-> case ("female") {
->->-> // script2
->-> }
-> }
}

show menu ("What is gender?", Object.gender_string_list, false) {
-> ScriptDictionaryItem (Object.gender_string_list, result)
}

get input {
-> ScriptDictionaryItem (Object.gender_string_list, result)
}

------------

and you can combine string dictionaries and script dictionaries, some examples:

Function: gender_function
msg ("What is your gender?")
msg ("(1) male or (2) female)")
get input {
-> if (ToInt (result) = 1 or ToInt (result) = 2) {
->-> invoke (ScriptDictionaryItem (Object.gender_script_dictionary, StringDictionaryItem (Object.gender_string_dictionary, result)))
-> } else {
->-> gender_function
-> }
}

Object: 'whatever'
<attr name="gender_string_dictionary" type="simplestringdictionary">1=male;2=female</attr>
<attr name="gender_script_dictionary" type="scriptdictionary">
-> <item key="male">
->-> // script1
-> </item>
-> <item key="female">
->-> // script2
-> </item>
</attr>

what it's doing:

// you type in: 2
invoke (ScriptDictionaryItem (Object.gender_script_dictionary, StringDictionaryItem (Object.gender_string_dictionary, result)))

invoke (ScriptDictionaryItem (Object.gender_script_dictionary, StringDictionaryItem (Object.gender_string_dictionary, "2")))
invoke (ScriptDictionaryItem (Object.gender_script_dictionary, StringDictionaryItem_conversion_effect ("2"->"female")))
invoke (ScriptDictionaryItem (Object.gender_script_dictionary, female))
invoke (ScriptDictionaryItem_conversion_effect ("female"->script2))
invoke (script2)

---------------------------

lists ('foreach', 'for', 'ListCount', 'ListContains', etc):

are really just for creating a group of specific items, to thus then be able to act upon those (and ONLY those) items in that group you created.

however, the application of this functionality of lists ('foreach', 'for', etc) is extremely vast and diversified, for example, due to allowing you to do 'string comparisons' (extremely powerful~useful tool~tactic of coding), and etc cool stuff that I'm still not yet aware of myself, don't understand how to code-do-it yet, hehe.

what uses these created groups specific items:

equipment, spells~magic, monster classes, treasure~drop classes, combining items, randomization of all of these things, Scopes (all in game or all just for a room: exits, objects, visible objects, reachable objects, etc etc etc), dialogue options, party~team members, attributes (such as a 'level up' UI:user interface), rooms (for example, you want to add items to specific rooms after an event halfway through your game), map~grid making, etc etc etc

for*EACH* is for doing ALL~EVERY~*EACH* item in the group (list)
for ('this~these items only') is for specific items in the group (list)