**A tribute to coding for the sake of coding, by Amaikokonut **Found originally at http://naturingnurturing.blogspot.com/ ** But you know what? Do whatever you want with this code. *>> This agent exists to count the images in a spritefile. It's a TERRIBLE IDEA. new: simp 1 1 22932 "blank" 0 0 9000 mesg wrt+ targ 1000 "cuddly-tree" "_hand" 0 *To run a check, rtar this and mesg wrt+ targ 1000 imagename returnvariable 0 scrp 1 1 22932 1000 lock inst seta ov02 from *ov00 is number of images available in the sprite setv ov00 0 *first, make sure the image exists doif snax _p1_ eq 0 gsub tally stop endi **CHECK if autokill is on. Yes. That's right. Because what we're going to do *is INTENTIONALLY throw errors, and the player doesn't need to see that setv va00 wolf 15 0 andv va00 8 doif va00 eq 8 setv name "autokill" 0 else setv name "autokill" 1 *so we're going to turn it on now. >> setv va00 wolf 7 8 endi *and create a dummy agent new: simp 1 2 22932 _p1_ 9999 0 0 seta mv01 targ *now...to test... loop *targ your dummy agent targ mv01 *get its pose setv mv00 pose *add one to it addv mv00 1 mesg wrt+ targ 1000 mv00 0 0 *This literally won't work without waiting. *Because it needs time to set the message to the script and for the script to execute *Sadly this also means that each image takes a tick to count *meaning it can take several, several seconds to count something like say, creature *head sprites *Would really like to find a solution to this someday >: wait 0 * dbg: outv mv00 untl mv01 eq null inst targ ownr *if autokill was off in the beginning, turn it back off doif name "autokill" = 1 setv va00 wolf 7 0 endi gsub tally *This takes the total number of things and outputs it somehow subr tally *check _p2_'s type doif type _p2_ eq 2 *the "_hand" is a sort of special override for testing purposes. doif _p2_ eq "_hand" sets va00 _p1_ adds va00 " contains " adds va00 vtos ov00 adds va00 " images." rtar 1 2 10 mesg wrt+ targ 126 va00 pntr 0 dbg: outs va00 else *else, it's another string *targ the agent who sent it, and set it as a name variable targ mv02 dbg: outs "sending to string" setv name _p2_ mv00 endi *else, if it's an integer *send a message to the script specified in p2 elif type _p2_ eq 0 mesg wrt+ mv02 _p2_ ov00 0 0 endi retn endm scrp 1 2 22932 1000 pose _p1_ endm rscr enum 1 2 22932 kill targ next enum 1 1 22932 kill targ next endm