Development Forum |
|
Check all Creatures for chemicals/drives | |
|
Arnout
|
7/25/2017 | |
Hello all.
I've been trying to make a C3/DS script that once in a while checks Creatures for high drives/chemicals and then gives a certain reaction according to those drives/chemicals. While the script is currently working, I feel that there's a more efficient way to check on Creatures than the script is maintaining now. That's why I've got a few questions about the script that I've displayed below.
*Make the check-up agent
new: simp 1 1 26530 "blnk" 1 0 0
*Move to the DS or C3 creator
mvto va00 va01
*Set a timer
tick 1200
scrp 1 1 26530 9
setv va04 0
enum 4 0 0
addv va04 1
next
doif va04 gt 0
loop
rtar 4 0 0
untl chem 149 gt 0.5 or chem 150 gt 0.5 or chem 151 gt 0.5 or chem 159 gt 0.8
targ targ
doif dead eq 0 and aslp eq 0
setv va02 posx
setv va03 posy
new: simp 2 3 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
new: simp 2 8 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
new: simp 2 11 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
... |
1. Does a loop run once per timing script or is this one going to keep randomly targetting Creatures until it finds a Creature with one of the high chemicals?
2. Is it possible to select all Creatures at once, then filter out the ones with high chemicals/drives and then spawn agents near all of these Creatures without having to add position variables for each Creature? Is it even possible to store multiple Creature positions in one script?
I know that this is a bit out of the blue, but I think that I may have figured something out that helps Creatures combat Eat Elevator Syndrome. However, if this script continuously selects random Creatures, I can imagine that the C3/DS engine would get a bit wrought-up after running it for a while. That's why I'm looking for a more effective way to execute this script.
Thanks if you made it this far. :p |
Peppery One
Papriko
|
7/25/2017 | 2 |
This loop will run stubbornly until it finds at least one creature that fits the criteria. In fact if it finds nothing else, it'll keep randomly targetting as quick as it can. If you put it inside an inst, you'd have yourself a patent recipe for a softlock/freeze.
If you do a count without any conditions whatsoever, you can use the totl command to get the number of creatures. The entiresetv va04 0
enum 4 0 0
addv va04 1
next | block would condense down towhich would run much quicker than the enumeration.
"targ targ" is, quite frankly, useless. Not trying to be a jerk, but it's really not doing anything. Since targ is already targ, there is no reason re-targ the targ that's already targ, you know what I mean?
Anyway, have you considered to enum the entire main bulk of the code? Then you could skip the population count altogether, too
*Make the check-up agent
new: simp 1 1 26530 "blnk" 1 0 0
*Move to the DS or C3 creator
mvto va00 va01
*Set a timer
tick 1200
scrp 1 1 26530 9
enum 4 0 0
doif chem 149 gt 0.5 or chem 150 gt 0.5 or chem 151 gt 0.5 or chem 159 gt 0.8
doif dead eq 0 and aslp eq 0
setv va02 posx
setv va03 posy
new: simp 2 3 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
new: simp 2 8 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
new: simp 2 11 26530 "blnk" 1 0 0
mvto va02 va03
tick 5
...
endi
endi
next | If you feel cheeky, you could even pull together those two doifs, but then the line gets a little cluttered.
If no creatures are present, I am not sure if the code is skipped entirely or if it is only run once with targ = null. You might wanna add an exception into your doif mess for that.
Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis... |
Arnout
|
7/26/2017 | |
Thank you for your advice. Regarding the targ targ, I wasn't really awake when I wrote that line, so nevermind that.
The code is effectively breaking Creatures out of Eat Elevator now, so I'll do some more testing to see if there's any effects on the longer term and I'll upload the script on here later on. |
|