Storing turn number in an array, modifying it and using it as condition
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
- PapaSmurfReloaded
- Posts: 820
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Storing turn number in an array, modifying it and using it as condition
I am in need of some help.
In my Bloody Mod add-on, I wanted to make it so that blood stains and corpses dissapears x turns (decay time) after they are created (lets say 3 turns.)
Such action requires me to store the location of the remains when they are created, I have managed to get it working this far.
I guess I have to create another array which stores the turn when each stain is created, add 3 to its value, then put that value as the condition for erasing of that individual stain.
However, for some reason thinking about how to code the second part confuses me.
Here is a short version of the code I am currently using.
In my Bloody Mod add-on, I wanted to make it so that blood stains and corpses dissapears x turns (decay time) after they are created (lets say 3 turns.)
Such action requires me to store the location of the remains when they are created, I have managed to get it working this far.
I guess I have to create another array which stores the turn when each stain is created, add 3 to its value, then put that value as the condition for erasing of that individual stain.
However, for some reason thinking about how to code the second part confuses me.
Here is a short version of the code I am currently using.
Code: Select all
[event]
name=last breath
first_time_only=no
[filter]
type=Skeleton,Skeleton Archer,Revenant,Deathblade,Bone Shooter,Death Knight,Draug,Banebow,Chocobone,Lich,Ancient Lich
[/filter]
{PLACE_IMAGE items/bones.png $x1 $y1}
[store_locations]
variable=bm_bones_loc
mode=append
x,y=$x1,$y1
[/store_locations]
[/event]
Code: Select all
[event]
name=turn end
first_time_only=no
{FOREACH bm_bones_loc i}
[remove_item]
x,y=$bm_bones_loc[$i].x,$bm_bones_loc[$i].y
image=items/bones.png
[/remove_item]
{NEXT i}
{CLEAR_VARIABLE i}
[redraw]
[/redraw]
[/event]
Last edited by Pentarctagon on October 28th, 2018, 3:14 am, edited 1 time in total.
Reason: [c] -> [code]
Reason: [c] -> [code]
- Pentarctagon
- Project Manager
- Posts: 5533
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Storing turn number in an array, modifying it and using it as condition
Not really related to your question, but as an fyi, NEXT already clears the index variable, so you don't need to be doing that yourself.
As for your actual question, you don't need to use a separate array - you could do something like this:
Or alternatively, if all you need is the x and y values from the location:
Then in your second code block, check if
As for your actual question, you don't need to use a separate array - you could do something like this:
{VARIABLE bm_bones_loc["$($bm_bones_loc.length-1)"].turn "$($turn_number+3)"}
Or alternatively, if all you need is the x and y values from the location:
Code: Select all
[set_variables]
name=bm_bones_loc
mode=append
[value]
x=$x1
y=$y1
turn="$($turn_number+3)"
[/value]
[/set_variables]
bm_bones_loc[$i].turn
equals $turn_number
, and then use [remove_item] if it is.99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
- skeptical_troll
- Posts: 498
- Joined: August 31st, 2015, 11:06 pm
Re: Storing turn number in an array, modifying it and using it as condition
It looks like a nested event would work better in this case. Inside your first event, create the event
name =turn $($turn_number +3)
where you remove the image. Make sure you set delayed_variable_substitition = no
to get the right coordinatesRe: Storing turn number in an array, modifying it and using it as condition
y i think i agree with troll, not saying it's better, but i think it's much more simple..
i wonder what will happen if 3 units die on same hex, one at turn 1, other at turn 2 and other on turn 3, would remove_item clear all 3 images or just one of them.. ?
Code: Select all
[event]
name=last breath
first_time_only=no
[filter]
type=Skeleton,Skeleton Archer,Revenant,Deathblade,Bone Shooter,Death Knight,Draug,Banebow,Chocobone,Lich,Ancient Lich
[/filter]
{PLACE_IMAGE items/bones.png $x1 $y1}
{VARIABLE temp_turn_number $turn_number}
{VARIABLE_OP temp_turn_number add 3}
[event]
name=turn $temp_turn_number
first_time_only=yes
delayed_variable_substitition=no ## if it doesn't work this way then try to remove it.. I'm not sure if it's 100% needed, but it's highly likely
### (otherwise $temp_turn_number MAY not be converted into anything.. it will stay with $ sign and never work as intended.
## other variables may also have hard times to be converted.. when it's event inside event.. magic may start happening.. may not;) depends on situation.
[remove_item]
x,y=$x1,$y1 ### if it doesnt work try to use $|x1 and $|y1 instead.. event inside event may cause differences..
### if you dont put delay variable substitution $x1 $y1 would probably work as it is, but event itself probably wouldnt... need testing. not 100% sure.
image=items/bones.png
[/remove_item]
[/event]
{CLEAR_VARIABLE temp_turn_number} ## idk if this needed or not.. don't think it will break anything with event inside event if you clear it.
[/event]
- PapaSmurfReloaded
- Posts: 820
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: Storing turn number in an array, modifying it and using it as condition
Well I guess all of the images with the same name and path would be deleted, I thought about that too but it would just be a minor issue.enclave wrote: ↑October 28th, 2018, 1:45 pm y i think i agree with troll, not saying it's better, but i think it's much more simple..i wonder what will happen if 3 units die on same hex, one at turn 1, other at turn 2 and other on turn 3, would remove_item clear all 3 images or just one of them.. ?Code: Select all
[event] name=last breath first_time_only=no [filter] type=Skeleton,Skeleton Archer,Revenant,Deathblade,Bone Shooter,Death Knight,Draug,Banebow,Chocobone,Lich,Ancient Lich [/filter] {PLACE_IMAGE items/bones.png $x1 $y1} {VARIABLE temp_turn_number $turn_number} {VARIABLE_OP temp_turn_number add 3} [event] name=turn $temp_turn_number first_time_only=yes delayed_variable_substitition=no ## if it doesn't work this way then try to remove it.. I'm not sure if it's 100% needed, but it's highly likely ### (otherwise $temp_turn_number MAY not be converted into anything.. it will stay with $ sign and never work as intended. ## other variables may also have hard times to be converted.. when it's event inside event.. magic may start happening.. may not;) depends on situation. [remove_item] x,y=$x1,$y1 ### if it doesnt work try to use $|x1 and $|y1 instead.. event inside event may cause differences.. ### if you dont put delay variable substitution $x1 $y1 would probably work as it is, but event itself probably wouldnt... need testing. not 100% sure. image=items/bones.png [/remove_item] [/event] {CLEAR_VARIABLE temp_turn_number} ## idk if this needed or not.. don't think it will break anything with event inside event if you clear it. [/event]
EDIt: I tried to do what troll and enclave suggest, and for some reason these nested events don't work.
Re: Storing turn number in an array, modifying it and using it as condition
y if u wanted to create it to perfection you could probably then use it in some kind of arrays and recreate the needed amount.. but it's probbaly overcomplicating things.. plus im not sure if all 3 will be removed to be honest;)
Ok, then try to put [chat] message="x1 $x1 y1 $y1 x1 $|x1 y1 $|y1 into last breath and turn number event" (change turn number into turn end, so it will display message straight away maybe.. without waiting 3 turns..) we will see if variables are nil or have anything there..
( side X turn Y end ) the event name
I dont even know if last breath will have $x1, $y1 or it will be $unit.x $unit.y instead... so it just need to be tested with chat message to make sure.
Ok, then try to put [chat] message="x1 $x1 y1 $y1 x1 $|x1 y1 $|y1 into last breath and turn number event" (change turn number into turn end, so it will display message straight away maybe.. without waiting 3 turns..) we will see if variables are nil or have anything there..
( side X turn Y end ) the event name
I dont even know if last breath will have $x1, $y1 or it will be $unit.x $unit.y instead... so it just need to be tested with chat message to make sure.
Last edited by enclave on October 28th, 2018, 2:38 pm, edited 1 time in total.
- skeptical_troll
- Posts: 498
- Joined: August 31st, 2015, 11:06 pm
Re: Storing turn number in an array, modifying it and using it as condition
I remember having some headache with nested events of this kind. I think the syntax requires you to put quotes, i.e.
name="turn $(3 + $turn_number)"
and you need the delayed substitution set to no.- PapaSmurfReloaded
- Posts: 820
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: Storing turn number in an array, modifying it and using it as condition
Thats below is tested and 100% working (at least on Skeleton)
Code: Select all
[event]
name=last breath
first_time_only=no
[filter]
type=Skeleton,Skeleton Archer,Revenant,Deathblade,Bone Shooter,Death Knight,Draug,Banebow,Chocobone,Lich,Ancient Lich
[/filter]
{PLACE_IMAGE items/bones.png $x1 $y1}
{VARIABLE temp_turn_number $turn_number}
{VARIABLE_OP temp_turn_number add 1}
[event]
name=turn $temp_turn_number
first_time_only=yes
delayed_variable_substitution=no ## if it doesn't work this way then try to remove it.. I'm not sure if it's 100% needed, but it's highly likely
### (otherwise $temp_turn_number MAY not be converted into anything.. it will stay with $ sign and never work as intended.
## other variables may also have hard times to be converted.. when it's event inside event.. magic may start happening.. may not;) depends on situation.
[remove_item]
x,y=$x1,$y1 ### if it doesnt work try to use $|x1 and $|y1 instead.. event inside event may cause differences..
### if you dont put delay variable substitution $x1 $y1 would probably work as it is, but event itself probably wouldnt... need testing. not 100% sure.
image=items/bones.png
[/remove_item]
[/event]
{CLEAR_VARIABLE temp_turn_number} ## idk if this needed or not.. don't think it will break anything with event inside event if you clear it.
[/event]
i
tion=no" (should be delayed_variable_substitu
tion=no )- PapaSmurfReloaded
- Posts: 820
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: Storing turn number in an array, modifying it and using it as condition
Happens.
Thank you, I'll see how it fares.
- PapaSmurfReloaded
- Posts: 820
- Joined: November 17th, 2007, 1:10 pm
- Location: Argentina
Re: Storing turn number in an array, modifying it and using it as condition
Well enclave, it works wonderfully. Thank you.
Bloody Mod updated, now stains and remains decay over time and you set how fast with a slider.
EDIT: Thanks everybody else for the ideas too.
/topic
Bloody Mod updated, now stains and remains decay over time and you set how fast with a slider.
EDIT: Thanks everybody else for the ideas too.
/topic
Re: Storing turn number in an array, modifying it and using it as condition
very welcome sorry for mistype.. could save u tons of time..