Print Out List With A Delay Between Items
Fyrdraca
24 Dec 2015, 23:05Like it says in the subject line, folks. How do I list out items with a delay between each item of five seconds or so? I tried using SetTimeout, but haven't had luck. Can't access the parameters of the loop. I've about given myself an aneurysm trying to fix this.

jaynabonne
24 Dec 2015, 23:38Yes, you can't pass information directly into the script that SetTimeout runs. It's run in a different context, and the variables are all dead at that point. But you can store the values as attributes of an object (game, player, other custom object). It's not pretty but it is doable.
Fyrdraca
24 Dec 2015, 23:49jaynabonne wrote:Yes, you can't pass information directly into the script that SetTimeout runs. It's run in a different context, and the variables are all dead at that point. But you can store the values as attributes of an object (game, player, other custom object). It's not pretty but it is doable.
I've been trying that very thing, but I still haven't been able to get it working right. In some attempts, it just lists one of the items several times; in others, it won't recognize a parameter. Could I trouble you to conjure a working example for me?
Fyrdraca
25 Dec 2015, 05:43jaynabonne wrote:Yes, you can't pass information directly into the script that SetTimeout runs. It's run in a different context, and the variables are all dead at that point. But you can store the values as attributes of an object (game, player, other custom object). It's not pretty but it is doable.
Let me give you a snippet of the code as an example:
if (player.attack_roll > shark.armor_class-1) {
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
SetTimeout (5*player.turn_num) {
msg(StringListItem (player.battleLog, player.turn_num-1))
}
shark.hit_points = shark.hit_points - player.damage_roll
player.turn_num = player.turn_num + 1
if (shark.hit_points < 1) {
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.")
SetTimeout (5*player.turn_num) {
msg(StringListItem (player.battleLog, player.turn_num-1))
}
}
}
The problem here is that the entire battle processes immediately, so using player.turn_num as an index when it increments over the course of the loop doesn't help - because the player.turn_num has incremented x times already. On every one of these delayed messages, player.turn_num-1 is the same value.
I'm trying a new thing (and starting to feel like Wil E Coyote) where I have a loop outside of the main loop. That is to say, the main loop calculates combat and the outer loop after that displays the outcome of the combat. I still need to find a couple of list functions; one to calculate the length of a list, and another to clear a list. Right now, it looks something like this (I know player.battleLog.length is pseudocode):
for (1, 1, player.battleLog.length, 1) {
SetTimeout (5*player.turn_num){
msg(StringListItem(player.battleLog, player.turn_num-1))
player.turn_num = player.turn_num + 1
}
}
HegemonKhan
25 Dec 2015, 05:47if you don't mind having an empty line between your list of items (and a unison~constant delay time), I think this would be the simpliest way to do it:
http://docs.textadventures.co.uk/quest/ ... riter.html (textwriter)
(HK edit, sorry I thought I had already posted this link, my bad)
(how would we put the 'TextFX_Typewriter's text on the same line as the msg's dynamic text in quest? forgive me if this is a stupid question but my mind is failing me at the moment. Also, is there any way of not going to a newline, and~or going back up or down lines?)
(if you want a non-unison, a dynamic delay time: ie 5 second wait then a 10 second wait then a 2 second wait etc etc etc, let me know, as that's a quick-easy fix, for me to help you with doing)
// outputs:
if you want these items to be hyperlinks, let me know, as that's also a quick fix, though it requires a bit more (advance-complex using text processor commands and Commands) coding.
-----------
P.S.
http://docs.textadventures.co.uk/quest/ ... lists.html (using lists)
http://docs.textadventures.co.uk/quest/ ... aries.html (using dictionaries)
http://docs.textadventures.co.uk/quest/scripts/ (more functions~scripts)
http://docs.textadventures.co.uk/quest/functions/ (categorical ordering)
http://docs.textadventures.co.uk/quest/ ... tions.html (alphabetical ordering)
and much more useful documentation (explore around and ask questions if you don't understand anything):
http://docs.textadventures.co.uk/quest/
guides:
http://docs.textadventures.co.uk/quest/tutorial/
http://docs.textadventures.co.uk/quest/guides/
viewforum.php?f=18 (more guides: libraries and code samples)
very useful
---------
P.S.S.
my code above, is a manual way (granting more control-functionality) of outputting a list, but there's a built-in way of doing so:
http://docs.textadventures.co.uk/quest/ ... ylist.html
for example:
// game.sex_list = split ("male;female", ";")
DisplayList (game.sex_list, true) // if you use-type-in 'true', then you DO get the numbering in front of the items being shown-outputed-listed (see my code output for example)
DisplayList (game.sex_list, false) // if you use-type-in 'false', then you do NOT get any numbering in front of the items listed being shown-outputed-listed
http://docs.textadventures.co.uk/quest/ ... riter.html (textwriter)
(HK edit, sorry I thought I had already posted this link, my bad)
(how would we put the 'TextFX_Typewriter's text on the same line as the msg's dynamic text in quest? forgive me if this is a stupid question but my mind is failing me at the moment. Also, is there any way of not going to a newline, and~or going back up or down lines?)
(if you want a non-unison, a dynamic delay time: ie 5 second wait then a 10 second wait then a 2 second wait etc etc etc, let me know, as that's a quick-easy fix, for me to help you with doing)
numbering_variable = 0
foreach (item_placeholder_variable, your_Object_name.your_list_Attribute_name) {
numbering_variable = numbering_variable + 1
msg (numbering_variable + ". " + item_placeholder_variable)
TextFX_Typewriter("", number_for_speed_time_in_milliseconds)
}
// outputs:
1. your_item_1
2. your_item_2
3. your_item_3
4. your_item_4
// etc etc etc
if you want these items to be hyperlinks, let me know, as that's also a quick fix, though it requires a bit more (advance-complex using text processor commands and Commands) coding.
-----------
P.S.
http://docs.textadventures.co.uk/quest/ ... lists.html (using lists)
http://docs.textadventures.co.uk/quest/ ... aries.html (using dictionaries)
http://docs.textadventures.co.uk/quest/scripts/ (more functions~scripts)
http://docs.textadventures.co.uk/quest/functions/ (categorical ordering)
http://docs.textadventures.co.uk/quest/ ... tions.html (alphabetical ordering)
and much more useful documentation (explore around and ask questions if you don't understand anything):
http://docs.textadventures.co.uk/quest/
guides:
http://docs.textadventures.co.uk/quest/tutorial/
http://docs.textadventures.co.uk/quest/guides/
viewforum.php?f=18 (more guides: libraries and code samples)
very useful

---------
P.S.S.
my code above, is a manual way (granting more control-functionality) of outputting a list, but there's a built-in way of doing so:
http://docs.textadventures.co.uk/quest/ ... ylist.html
for example:
// game.sex_list = split ("male;female", ";")
DisplayList (game.sex_list, true) // if you use-type-in 'true', then you DO get the numbering in front of the items being shown-outputed-listed (see my code output for example)
DisplayList (game.sex_list, false) // if you use-type-in 'false', then you do NOT get any numbering in front of the items listed being shown-outputed-listed
Fyrdraca
25 Dec 2015, 06:06Thanks. It's not that I can't print out the combat log correctly, it's that I can't print out the combat log correctly AND with a delay between each item in the list. That's what I'm trying to figure out.
HegemonKhan
25 Dec 2015, 06:11my method of using the typewriter's delay should do this for you, see my previous post's code again.
----------
HK edit:
to increment (add)-decrement (subtract)-multiply-divide-modulus (remainder), you got to do this:
Object_name.Attribute_name = Object_name.Attribute_name + value
Object_name.Attribute_name = Object_name.Attribute_name - value
Object_name.Attribute_name = Object_name.Attribute_name * value
Object_name.Attribute_name = Object_name.Attribute_name / value
Object_name.Attribute_name = Object_name.Attribute_name % value
examples:
// initial: player.strength = 50
player.strength = player.strength + 25
// new: player.strength = 75
player.strength = player.strength - 15
// new (using the '50' as base): player.strength = 35
player.strength = player.strength * 3
// new (using the '50' as base): player.strength = 150
player.strength = player.strength / 5
// new (using the '50' as base): player.strength = 10
player.strength = player.strength % 10
// new (using the '50' as base): player.strength = 0
// remember this is the REMAINDER, not the quotient. The modulus operator (%) works well for cyclic usage (such as time: clock.seconds = value % 60, clock.military_hours = value % 24, clock.civilian_hours = value % 12), and has some other uses too
----------
HK edit:
Fyrdraca wrote:The problem here is that the entire battle processes immediately, so using player.turn_num as an index when it increments over the course of the loop doesn't help - because the player.turn_num has incremented x times already. On every one of these delayed messages, player.turn_num-1 is the same value.
to increment (add)-decrement (subtract)-multiply-divide-modulus (remainder), you got to do this:
Object_name.Attribute_name = Object_name.Attribute_name + value
Object_name.Attribute_name = Object_name.Attribute_name - value
Object_name.Attribute_name = Object_name.Attribute_name * value
Object_name.Attribute_name = Object_name.Attribute_name / value
Object_name.Attribute_name = Object_name.Attribute_name % value
examples:
// initial: player.strength = 50
player.strength = player.strength + 25
// new: player.strength = 75
player.strength = player.strength - 15
// new (using the '50' as base): player.strength = 35
player.strength = player.strength * 3
// new (using the '50' as base): player.strength = 150
player.strength = player.strength / 5
// new (using the '50' as base): player.strength = 10
player.strength = player.strength % 10
// new (using the '50' as base): player.strength = 0
// remember this is the REMAINDER, not the quotient. The modulus operator (%) works well for cyclic usage (such as time: clock.seconds = value % 60, clock.military_hours = value % 24, clock.civilian_hours = value % 12), and has some other uses too
Fyrdraca
25 Dec 2015, 06:21I'm familiar with the typewriter delay, but 1) it doesn't work in the foreach loop you posted, and 2) even if it did, that's not what I need this function to do. I need it to print an item from a list in its entirety, pause for 5 seconds, print the next item in its entirety, pause for 5 seconds, etc. Thanks though! 

HegemonKhan
25 Dec 2015, 06:26it doesn't? doh!, logically it seemed like it would (never tested it), hmm... now I'm curious why it doesn't work, as it should (seemingly-logical) work..., lol
well, Jay can help you do it then through the Timer method (I'm not familiar with using Timers, as I don't like using them)
---------
you could try... the 'on ready' ( http://docs.textadventures.co.uk/quest/ ... ready.html ) Function with using my code: you'd put the 'on ready' after-below the typewriter code line (and still INSIDE of the 'foreach' loop), but this probably won't work as well, sighs.
well, Jay can help you do it then through the Timer method (I'm not familiar with using Timers, as I don't like using them)
---------
you could try... the 'on ready' ( http://docs.textadventures.co.uk/quest/ ... ready.html ) Function with using my code: you'd put the 'on ready' after-below the typewriter code line (and still INSIDE of the 'foreach' loop), but this probably won't work as well, sighs.
HegemonKhan
25 Dec 2015, 06:37here, correcting your code, so it now (should - HK crosses his fingers) list your items:
(fixed up a lot of the indenting, more than I commented on below)
(fixed up a lot of the indenting, more than I commented on below)
if (player.attack_roll > shark.armor_class-1) {
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1 // here's a new code line you need, and you need to indent too
msg(StringListItem (player.battleLog, player.turn_num)) // here's a fixed up code line too, you need to indent too
}
shark.hit_points = shark.hit_points - player.damage_roll
player.turn_num = player.turn_num + 1
if (shark.hit_points < 1) {
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.") // this needed to be indented too
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1 // here's a new code line you need, you need to indent too
msg(StringListItem (player.battleLog, player.turn_num)) // here's a fixed up code line too
}
}
}
HegemonKhan
25 Dec 2015, 07:07P.S.
here's a link to a guide I made on using lists~dictionaries:
viewtopic.php?f=18&t=5137
and here's some more fancy usage lists and dictionaries, which will help you (if you can understand it ~ as it's poor code - as it was back when I was learning how to use lists and dictionaries myself, lol), if you want to take a look at it:
viewtopic.php?f=18&t=5138
ask if you got any questions or need help with anything!
here's a link to a guide I made on using lists~dictionaries:
viewtopic.php?f=18&t=5137
and here's some more fancy usage lists and dictionaries, which will help you (if you can understand it ~ as it's poor code - as it was back when I was learning how to use lists and dictionaries myself, lol), if you want to take a look at it:
viewtopic.php?f=18&t=5138
ask if you got any questions or need help with anything!
Fyrdraca
25 Dec 2015, 07:38Thanks HK, this is some major headway. It works perfectly, but with one interesting major catch: it works backwards.
I'm sorry if the indenting is messed up; I pasted this straight out of Quest after it auto-indented. I applied your suggestions to the entire algorithm and got this:
I ran it and came up with this output:
Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark twists through and knocks aside your outstretched arms, savaging your body for 4 points of damage.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 3 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 4 points of damage.
I'm sorry if the indenting is messed up; I pasted this straight out of Quest after it auto-indented. I applied your suggestions to the entire algorithm and got this:
msg ("interestingly, this is perfect, but it goes backwards")
shark.armor_class = 8
shark.hit_die = "1d4"
shark.hit_points = 8 + DiceRoll("1d4")
player.armor_class = 10 + player.dexterity
turn_max = DiceRoll("1d6")
player.turn_num = 1
for (1, 1, turn_max, 1) {
player.attack_roll = DiceRoll("1d20") + player.dexterity
player.damage_roll = DiceRoll("1d3") + player.dexterity
shark.attack_roll = DiceRoll("1d20")
shark.damage_roll = DiceRoll(shark.hit_die)
if ((player.hit_points>0) and (shark.hit_points>0)) {
if (player.attack_roll > shark.armor_class-1) {
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
shark.hit_points = shark.hit_points - player.damage_roll
player.turn_num = player.turn_num + 1
if (shark.hit_points < 1) {
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
}
}
else {
list add(player.battleLog,"You stab out at the attacking shark, but your dagger glances off of its rough hide.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
player.turn_num = player.turn_num + 1
}
if (shark.hit_points>0) {
if (shark.attack_roll > player.armor_class-1) {
list add(player.battleLog,"The shark twists through and knocks aside your outstretched arms, savaging your body for " + shark.damage_roll + " points of damage.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
player.hit_points = player.hit_points - shark.damage_roll
player.bloodied = true
player.turn_num = player.turn_num + 1
if (player.hit_points <1) {
list add(player.battleLog,"Trauma and loss of blood makes your head swim. Your vision darkens and the last thing you feel is being shaken and sheared by the predator you failed to overcome.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
finish
}
}
}
else {
list add(player.battleLog,"The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
player.turn_num = player.turn_num + 1
}
}
}
}
if ((player.hit_points > 0) and (shark.hit_points > 0)) {
list add(player.battleLog,"The water is a boil of bubbles and blood, both you and the shark are in a frenzy, both trying to kill the other. With a flick of its tail, the shark turns and hurries away in search of a more compliant meal.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
}
shark.hit_points = 8 + DiceRoll("1d4")
I ran it and came up with this output:
Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark twists through and knocks aside your outstretched arms, savaging your body for 4 points of damage.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 2 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 3 points of damage.
The shark tries to get a purchase on your body, but you manage to twist away from it's gnashing teeth.
You bury your dagger in the thrashing shark's head for 4 points of damage.
HegemonKhan
25 Dec 2015, 07:42I just fixed up the indenting, in case you might have had your scripts out of order and~or not nested correctly, I know that dealing with formatting is annoying and wonky... laughs
---------
I'm not sure yet why it's going backwards (not familiar enough yet with your code...), but I quickly see the 'for' isn't set up correctly:
http://docs.textadventures.co.uk/quest/scripts/for.html
for (placeholder_variable_for_each_of_your_iterated_items, start_value, end_value, optional: interval_skip_value ~ it automatically defaults to 1, no skipping) { scripts }
(your placeholder variable, and actually ANY VARIABLE AND~OR the NAME of things, usually can't be a number or start with a number, at least with most programming languages, not sure about quest, but regardless you shouldn't do it, as that number can-could cause issues)
from the 'using lists' section in the quest docs, another example:
----------
P.S.
generally, 'foreach' is used in quest, as you got List and Dictionary Attributes, whereas in quest 'for' isn't as often needed, as it is used a lot more in the normal programming languages.
---------
I'm not sure yet why it's going backwards (not familiar enough yet with your code...), but I quickly see the 'for' isn't set up correctly:
http://docs.textadventures.co.uk/quest/scripts/for.html
for (placeholder_variable_for_each_of_your_iterated_items, start_value, end_value, optional: interval_skip_value ~ it automatically defaults to 1, no skipping) { scripts }
(your placeholder variable, and actually ANY VARIABLE AND~OR the NAME of things, usually can't be a number or start with a number, at least with most programming languages, not sure about quest, but regardless you shouldn't do it, as that number can-could cause issues)
from the 'using lists' section in the quest docs, another example:
for (myItem, 0, ListCount(myList) - 1) {
msg ("Current item is " + ObjectListItem(myList,myItem).name)
}
----------
P.S.
generally, 'foreach' is used in quest, as you got List and Dictionary Attributes, whereas in quest 'for' isn't as often needed, as it is used a lot more in the normal programming languages.
Fyrdraca
25 Dec 2015, 08:00You're the best. I'm gonna keep working at it. I'll check back here later to see if you came up with anything. Merry Christmas, HK!
HegemonKhan
25 Dec 2015, 08:01also, you may want to look at my own combat code, it could help you at least with ideas, (as awesomely you too seem to be making an RPG, I love RPGs, hehe, and am trying to learn to make one myself too):
viewtopic.php?f=10&t=3348&start=120#p22483
(be warned: this is very old and poor~bad code, with quite a lot of unneeded code lines, as this was when I was learning this stuff for the first time)
and the abrevs (I got the damage and resistance abrevs mixed up too, sorry about the abrevs, this is really old and I've learned to never use abrevs ever again, lol):
viewtopic.php?f=10&t=3348&start=120#p22486
---------
P.S.
Merry Christmas to you too!
(don't ruin it with struggling with quest and coding... lol, save the headaches and migraines for after Christmas)
viewtopic.php?f=10&t=3348&start=120#p22483
(be warned: this is very old and poor~bad code, with quite a lot of unneeded code lines, as this was when I was learning this stuff for the first time)
<asl version="530">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d83ba5bb-2e3c-4f31-80c9-3e88a2dc082c</gameid>
<version>1.0</version>
<pov type="object">player</pov>
<start type="script">
cc
</start>
<turns type="int">0</turns>
<statusattributes type="stringdictionary">turns = </statusattributes>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="defaultplayer" />
<inherit name="pc" />
<cur_hp type="int">999</cur_hp>
<max_hp type="int">999</max_hp>
<str type="int">100</str>
<end type="int">100</end>
<dex type="int">100</dex>
<agi type="int">100</agi>
<spd type="int">100</spd>
<hc type="int">100</hc>
<pd type="int">100</pd>
<pr type="int">100</pr>
</object>
<object name="orc1">
<inherit name="editor_object" />
<inherit name="npc" />
<hostile type="boolean">true</hostile>
<dead type="boolean">false</dead>
<alias>orc</alias>
<cur_hp type="int">999</cur_hp>
<max_hp type="int">999</max_hp>
<str type="int">25</str>
<end type="int">25</end>
<dex type="int">25</dex>
<agi type="int">25</agi>
<spd type="int">25</spd>
<hc type="int">25</hc>
<pd type="int">25</pd>
<pr type="int">25</pr>
</object>
</object>
<turnscript name="game_turns">
<enabled />
<script>
sa
game.turns = game.turns + 1
</script>
</turnscript>
<command name="fight">
<pattern>fight #text#</pattern>
<script>
battle_system (game.pov,text)
</script>
</command>
<type name="char">
<cur_hp type="int">0</cur_hp>
<drop type="boolean">false</drop>
<defending type="boolean">false</defending>
<max_hp type="int">0</max_hp>
<str type="int">0</str>
<end type="int">0</end>
<dex type="int">0</dex>
<agi type="int">0</agi>
<spd type="int">0</spd>
<hp type="int">0</hp>
<hc type="int">0</hc>
<pd type="int">0</pd>
<pr type="int">0</pr>
</type>
<type name="pc">
<inherit name="char" />
<statusattributes type="stringdictionary">hp = ;str = ;end = ;dex = ;agi = ;spd = ;hc = ;pd = ;pr = </statusattributes>
</type>
<type name="npc">
<inherit name="char" />
<dead type="boolean">false</dead>
<hostile type="boolean">false</hostile>
<displayverbs type="list">Look at; Talk; Fight</displayverbs>
</type>
<function name="cc">
msg ("What is your name?")
get input {
game.pov.alias = result
msg (" - " + game.pov.alias)
show menu ("What is your gender?", split ("male;female" , ";"), false) {
game.pov.gender = result
show menu ("What is your race?", split ("human;dwarf;elf" , ";"), false) {
game.pov.race = result
show menu ("What is your class?", split ("warrior;cleric;mage;thief" , ";"), false) {
game.pov.class = result
msg (game.pov.alias + " is a " + game.pov.gender + " " + game.pov.race + " " + game.pov.class + ".")
wait {
ClearScreen
}
}
}
}
}
</function>
<function name="sa">
game.pov.hp = game.pov.cur_hp + " / " + game.pov.max_hp
</function>
<function name="battle_system" parameters="self,text" type="boolean">
first_value = false
enemy = GetObject (text)
if (enemy = null) {
foreach (obj,AllObjects()) {
if (obj.alias=text) {
enemy = obj
}
}
}
if (enemy = null) {
msg ("There is no " + text + " here.")
first_value = false
}
else if (not Doesinherit (enemy,"npc")) {
msg ("You can not battle that!")
first_value = false
}
else if (not npc_reachable (enemy)) {
msg ("There is no " + enemy.alias + " in your vicinity.")
first_value = false
}
else if (GetBoolean (enemy,"dead") = true) {
msg (enemy.alias + " is already dead.")
first_value = false
}
else if (GetBoolean (enemy,"hostile") = false) {
msg (enemy.alias + " is not hostile.")
first_value = false
}
else if (battle_sequence (self,enemy) = true) {
msg ("The battle is over.")
first_value = true
}
return (first_value)
</function>
<function name="battle_sequence" parameters="self,enemy" type="boolean"><![CDATA[
second_value = false
if (enemy.dead = false) {
if (GetInt (self,"spd") > GetInt (enemy,"spd")) {
on ready {
msg ("You get to go first for this round")
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
}
on ready {
if (enemy.dead = false) {
if (enemy_battle_turn (self,enemy) = true) {
msg ("The round has ended.")
}
}
}
on ready {
battle_sequence (self,enemy)
}
}
else if (GetInt (self,"spd") < GetInt (enemy,"spd")) {
on ready {
msg (enemy.alias + " gets to go first for this round.")
if (enemy_battle_turn (self,enemy) = true) {
msg ("It is now your turn.")
}
}
on ready {
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
else {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
else if (GetInt (self,"spd") = GetInt (enemy,"spd")) {
if (RandomChance (50) = true) {
on ready {
msg ("You get to go first for this round")
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
}
on ready {
if (enemy_battle_turn (self,enemy) = true) {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
else {
on ready {
msg (enemy.alias + " gets to go first for this round.")
if (enemy_battle_turn (self,enemy) = true) {
msg ("It is now your turn.")
}
}
on ready {
if (self_battle_turn (self,enemy) = true) {
battle_sequence (self,enemy)
}
else {
msg ("The round has ended.")
}
}
on ready {
battle_sequence (self,enemy)
}
}
}
}
else {
second_value = true
}
return (second_value)
]]></function>
<function name="self_battle_turn" parameters="self,enemy" type="boolean"><![CDATA[
third_value = false
msg (self.alias + " has " + self.cur_hp + " HP left.")
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
wait {
show menu ("What is your battle choice?", split ("Attack;Defend;Cast;Item;Run", ";"), false) {
switch (result) {
case ("Attack") {
fourth_value = false
if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"spd")) = true) {
msg (enemy.alias + "evaded your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"Dex") - GetInt (self,"agi")) = true) {
msg (enemy.alias + "parried your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"dex")) = true) {
msg (enemy.alias + "blocked your attack!")
fourth_value = true
}
else if (RandomChance (GetInt (self,"dex") - GetInt (enemy,"spd")) = false) {
msg ("Your attack missed " + enemy.alias +"!")
fourth_value = true
}
else if (RandomChance (GetInt (enemy,"pr") - GetInt (self,"hc")) = true) {
msg ("Your attack got resisted by " + enemy.alias +"!")
fourth_value = true
}
else if (fourth_value = false) {
if (self.defending = true and enemy.defending = true) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * 2 * GetInt (self,"pd") / 2 + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
self.defending = false
}
else if (self.defending = true and enemy.defending = false) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * 2 * GetInt (self,"pd") + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
self.defending = false
}
else if (self.defending = false and enemy.defending = true) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * GetInt (self,"pd") / 2 + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
}
else if (self.defending = false and enemy.defending = false) {
enemy.cur_hp = enemy.cur_hp - (crit_hit (self) * GetInt (self,"pd") + GetInt (self,"pd") * (GetInt (self,"str") - GetInt (enemy,"end")) / 100)
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
}
}
}
case ("Defend") {
if (self.defending = false) {
self.defending = true
}
}
case ("Cast") {
self.defending = false
}
case ("Item") {
self.defending = false
}
case ("Run") {
self.defending = false
}
}
if (GetInt (enemy,"cur_hp") > 0) {
if (RandomChance (GetInt (self,"spd") - GetInt (enemy,"spd")) = true) {
msg ("You get an extra battle turn!")
self_battle_turn (self,enemy)
}
else {
msg ("Your battle turn is over.")
third_value = false
}
}
else if (GetInt (enemy,"cur_hp") <= 0) {
msg (enemy.alias + " is dead.")
msg ("You have won the battle!")
enemy.defending = false
enemy.dead = true
third_value = true
wait {
ClearScreen
}
}
}
}
return (third_value)
]]></function>
<function name="enemy_battle_turn" parameters="self,enemy" type="boolean"><![CDATA[
fifth_value = false
msg (self.alias + " has " + self.cur_hp + " HP left.")
msg (enemy.alias + " has " + enemy.cur_hp + " HP left.")
result = GetRandomInt (1,3)
switch (result) {
case (1) {
sixth_value = false
if (RandomChance (GetInt (self,"agi") - GetInt (enemy,"spd")) = true) {
msg ("You have evaded the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"dex") - GetInt (enemy,"agi")) = true) {
msg ("You have parried the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"agi") - GetInt (enemy,"dex")) = true) {
msg ("You have blocked the attack!")
sixth_value = true
}
else if (RandomChance (GetInt (enemy,"dex") - GetInt (self,"spd")) = false) {
msg (enemy.alias +"'s attack missed!")
sixth_value = true
}
else if (RandomChance (GetInt (self,"pr") - GetInt (enemy,"hc")) = true) {
msg ("You resisted the attack!")
sixth_value = true
}
else if (sixth_value = false) {
if (enemy.defending = true and self.defending = true) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * 2 * GetInt (enemy,"pd") / 2 + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
enemy.defending = false
}
else if (enemy.defending = true and self.defending = false) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * 2 * GetInt (enemy,"pd") + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
enemy.defending = false
}
else if (enemy.defending = false and self.defending = true) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * GetInt (enemy,"pd") / 2 + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
}
else if (enemy.defending = false and self.defending = false) {
self.cur_hp = self.cur_hp - (crit_hit (enemy) * GetInt (enemy,"pd") + GetInt (enemy,"pd") * (GetInt (enemy,"str") - GetInt (self,"end")) / 100)
msg (self.alias + " has " + self.cur_hp + " HP left.")
}
}
}
case (2) {
if (enemy.defending = false) {
msg (enemy.alias + " has choosen to defend itself.")
enemy.defending = true
}
}
case (3) {
enemy.defending = false
msg ("Cast")
}
}
if (GetInt (self,"cur_hp") > 0) {
if (RandomChance (GetInt (enemy,"spd") - GetInt (self,"spd")) = true) {
msg (enemy.alias + " gets an extra battle turn!")
wait {
enemy_battle_turn (self,enemy)
}
}
else {
msg (enemy.alias + " 's battle turn is over.")
fifth_value = true
}
}
else if (GetInt (self,"cur_hp") <= 0) {
msg (self.alias + " has died.")
msg ("GAME OVER")
finish
}
return (fifth_value)
]]></function>
<function name="npc_reachable" parameters="object" type="boolean">
value = false
foreach (x,ScopeReachableNotHeld ()) {
if (x=object) {
value = true
}
}
return (value)
</function>
<function name="crit_hit" parameters="object" type="int">
if (RandomChance (GetInt (object,"luck")) = true) {
value = 2
}
else {
value = 1
}
return (value)
</function>
</asl>
and the abrevs (I got the damage and resistance abrevs mixed up too, sorry about the abrevs, this is really old and I've learned to never use abrevs ever again, lol):
viewtopic.php?f=10&t=3348&start=120#p22486
01. cc = character creation function
02. sa = status attributes (mainly for implementing/displaying of ' cur / max ' stats) function
03. char = character object type ("pcs", "npcs", "monsters", etc., so, not a room, item, equipment, spell, etc)
04. pc = playable character object type ("player" characters / game.povs)
05. npc = non-playable character ("people", "monsters", and etc, so not a "player" character / not a game.pov, I'm going to have a hostility system, so any npc can be friendly or hostile, instead of having an actual "monster/enemy" type set aside)
06. hp = hit points (life) stat attribute
07. mp = mana points (magic) stat attribute
08. str = strength (physical damage, carry weight / equipment requirement, etc) stat attribute
09. end = endurance (physical defense, and etc) stat attribute
10. dex = dexterity (weapon~attack skill, think of this as "if your attack connects or not, do you 'whiff' or not", so not to gete confused with hc, and etc) stat attribute
11. agi = agility (dodging/evading, and etc) stat attribute
12. spd = speed (who goes first in battle, extra battle turns, escaping from battle, and etc) stat attribute
13. hc = hit chance (think of this more as piercing their armor or not, so not to get confused with dex, and etc) stat attribute
14. pd = physical damage stat attribute
15. fp = fire damage stat attribute
16. wp = water damage stat attribute
17. ap = air damage stat attribute
18. ed = earth damage stat attribute
19. ld = light damage stat attribute
20. dd = dark damage stat attribute
21. pr = physical resistance stat attribute
22. fr = fire resistance stat attribute
23. wr = water resistance stat attribute
24. ar = air resistance stat attribute
25. er = earth resistance stat attribute
26. lr = light resistance stat attribute
27. dr = dark resistance stat attribute
28. defending = boolean (reduces damage done for that character and increases the damage done by that character, if they chosoe to attack on the next turn)
29. escaped = boolean, run from battle (not completed/implemented yet)
30. hostile = boolean, any npc can be friendly or a(n) "monster/enemy", based upon a hostility scale (0-100), but not completed
31. dead = boolean
32. crit_hit = critical hit (bonus damage based upon luck)
33. luck = luck stat attribute
34. lvl = level stat attribute
35. exp = experience stat attribute
36. cash = cash stat attribute (currency)
37. lvlup = level up function
---------
P.S.
Merry Christmas to you too!

(don't ruin it with struggling with quest and coding... lol, save the headaches and migraines for after Christmas)
Fyrdraca
25 Dec 2015, 08:12It is an RPG...kinda. It's not meant to be a hack-and-slash. Your six fundamental statistics are meant to be applied to a very wide range of activities. You could go for weeks in-game without seeing a potential enemy. It's mostly meant to be atmospheric. This is the blurb I wrote about it elsewhere: "Domenico is a former merchant who has stepped out of retirement following the death of his wife and is dabbling in illicit maritime activities. The late fifteenth century Amalfi Coast is beautiful, but capricious."
I'm also considering an alternate display for the combat outcome, where I run the same basic algorithm, but instead of display "you miss/you take x damage" or "he misses/he takes x damage", it displays "you slash him across the torso" and "he swings and misses" and then shows the endgame dialogue like with the other one but makes a note of how much damage you took in the fight.
Yeah, my folks are really proud, but I've stressed over this algorithm and my mom has been telling me the same thing. You're probably right, but I'm really enjoying applying my fledgling coding skills toward something fun.
I'm also considering an alternate display for the combat outcome, where I run the same basic algorithm, but instead of display "you miss/you take x damage" or "he misses/he takes x damage", it displays "you slash him across the torso" and "he swings and misses" and then shows the endgame dialogue like with the other one but makes a note of how much damage you took in the fight.
Yeah, my folks are really proud, but I've stressed over this algorithm and my mom has been telling me the same thing. You're probably right, but I'm really enjoying applying my fledgling coding skills toward something fun.
HegemonKhan
25 Dec 2015, 08:27ah, I think I see why it's going backwards (HK crosses his fingers):
because that is the order that you add the items to your list and~or its due to: your looping + the 'if' scripts conditions:
the first item you add to your list (which is the left-most item in your list code, and thus also at index: 0):
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
the second item you add to your list (which is the second left-most item in your list code, and thus also at index: 1):
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.")
and your first output is the second item added to your list:
Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.
-------------
P.S.
tell me about it... I've worked on algorithms for like months! so NOT fun being a noob coder, lol. I literally have to think so hard, that I get actual headaches~migraines, in trying to figure out the logic~algorithm needed for it to work (and I don't always succeed as well, argh). I've never had to use my brain so hard before in my life, sighs. I wish I was a programming genius and all of this stuff is "child's play", but I'm not, sighs. I'm lucky if I can get an algorithm figured out and working in only 8 hrs, laughs.
------------
P.S.S.
awesome reference to Wile E. Coyote, I LOVE that cartoon, and I like the coyote, we're both smart-nerds, and I love his crazy+inventive ideas, laughs. I root-cheer for him, I want him to get the road runner, laughs. Of course, the cartoon never lets him succeed (also failure~struggle is something I'm familiar with), which endears him further to me (Wile E. Coyote == crazy ideas, brains~smart, and fails~struggles == HK, laughs). Wile E. Coyote is (one of) my favorite cartoon character(s).
awesome game:
http://www.gamefaqs.com/snes/588618-roa ... lley-rally
http://www.gamefaqs.com/snes/588618-roa ... eos/126379 (vid of game)
but REALLY REALLY hard, due to the Roadrunner's speed (you play as the road runner - it's like the sega sonic the hedge hog games but this game has inertia the road runner can't change acceleration+velocity easily, unlike sonic in the sega game - if I remember right, lol)... laughs.
because that is the order that you add the items to your list and~or its due to: your looping + the 'if' scripts conditions:
the first item you add to your list (which is the left-most item in your list code, and thus also at index: 0):
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
msg ("interestingly, this is perfect, but it goes backwards")
shark.armor_class = 8
shark.hit_die = "1d4"
shark.hit_points = 8 + DiceRoll("1d4")
player.armor_class = 10 + player.dexterity
turn_max = DiceRoll("1d6")
player.turn_num = 1
for (1, 1, turn_max, 1) {
player.attack_roll = DiceRoll("1d20") + player.dexterity
player.damage_roll = DiceRoll("1d3") + player.dexterity
shark.attack_roll = DiceRoll("1d20")
shark.damage_roll = DiceRoll(shark.hit_die)
if ((player.hit_points>0) and (shark.hit_points>0)) {
if (player.attack_roll > shark.armor_class-1) {
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
the second item you add to your list (which is the second left-most item in your list code, and thus also at index: 1):
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.")
msg ("interestingly, this is perfect, but it goes backwards")
shark.armor_class = 8
shark.hit_die = "1d4"
shark.hit_points = 8 + DiceRoll("1d4")
player.armor_class = 10 + player.dexterity
turn_max = DiceRoll("1d6")
player.turn_num = 1
for (1, 1, turn_max, 1) {
player.attack_roll = DiceRoll("1d20") + player.dexterity
player.damage_roll = DiceRoll("1d3") + player.dexterity
shark.attack_roll = DiceRoll("1d20")
shark.damage_roll = DiceRoll(shark.hit_die)
if ((player.hit_points>0) and (shark.hit_points>0)) {
if (player.attack_roll > shark.armor_class-1) {
list add(player.battleLog,"You bury your dagger in the thrashing shark's head for " + player.damage_roll + " points of damage.")
SetTimeout (5*player.turn_num) {
player.turn_num = player.turn_num - 1
msg(StringListItem (player.battleLog, player.turn_num))
}
shark.hit_points = shark.hit_points - player.damage_roll
player.turn_num = player.turn_num + 1
if (shark.hit_points < 1) {
list add(player.battleLog,"Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.")
and your first output is the second item added to your list:
Baring your teeth, now more angry than frightened, you withdraw your blade and stab down again as the shark's movements become sluggish. You slash indiscriminately, abandoning tactics, venting your rage, and your assailant jerks twice, then drifts to the bottom, trailing a billowing red cloud behind it. You surface and scream in pain and triumph.
-------------
P.S.
tell me about it... I've worked on algorithms for like months! so NOT fun being a noob coder, lol. I literally have to think so hard, that I get actual headaches~migraines, in trying to figure out the logic~algorithm needed for it to work (and I don't always succeed as well, argh). I've never had to use my brain so hard before in my life, sighs. I wish I was a programming genius and all of this stuff is "child's play", but I'm not, sighs. I'm lucky if I can get an algorithm figured out and working in only 8 hrs, laughs.
------------
P.S.S.
awesome reference to Wile E. Coyote, I LOVE that cartoon, and I like the coyote, we're both smart-nerds, and I love his crazy+inventive ideas, laughs. I root-cheer for him, I want him to get the road runner, laughs. Of course, the cartoon never lets him succeed (also failure~struggle is something I'm familiar with), which endears him further to me (Wile E. Coyote == crazy ideas, brains~smart, and fails~struggles == HK, laughs). Wile E. Coyote is (one of) my favorite cartoon character(s).
awesome game:
http://www.gamefaqs.com/snes/588618-roa ... lley-rally
http://www.gamefaqs.com/snes/588618-roa ... eos/126379 (vid of game)
but REALLY REALLY hard, due to the Roadrunner's speed (you play as the road runner - it's like the sega sonic the hedge hog games but this game has inertia the road runner can't change acceleration+velocity easily, unlike sonic in the sega game - if I remember right, lol)... laughs.