Announcement: Why not try our official idea generator for inspiration when making puzzles?


Caravel Forum : DROD Boards : Architecture : Scripting Question: counting enemies?
New Topic New Poll Post Reply
Poster Message
mauvebutterfly
Level: Smitemaster
Avatar
Rank Points: 720
Registered: 05-03-2015
IP: Logged
icon Scripting Question: counting enemies? (0)  
I think that I've gotten pretty good at scripting, but I have this one challenge idea that I'm stumped on how to implement.

You are in a room with a bunch of enemies (all of the same type) and you need to kill all but one of them before doing something else.

Is there a way to check this with scripting? I can check if there is a specific enemy within an area, but I don't know how to have the check fail if there are two or more enemies of the same type in that area.

(Actually, an awful idea that just occurred to me is that I could replace all the enemies with scripted enemies that all look and function identically to the regular enemy they would be replacing but are tracked as separate enemy types by the game engine. Shudder.)

I had the idea that I could simply have a variable increment every time you kill one of the enemies, but due to hot tiles it is easy (and in fact necessary) to kill multiple enemies on the same turn, which isn't something I seem to be able to track with scripting either.

Am I missing something obvious? Or am I going to have to change my challenge and/or redesign the room?

I swear I'll finish this hold someday...

____________________________
106th Skywatcher
08-25-2016 at 04:04 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Dragon Fogel
Level: Smitemaster
Rank Points: 2434
Registered: 06-21-2014
IP: Logged
icon Re: Scripting Question: counting enemies? (0)  
I'm no expert on scripting, but I can see a few options.

Possible-but-tedious: check every individual tile that the enemy can step on and increment a variable for each of them you find. If you're desperate enough to go for this, don't check at every turn as that will more than likely cause slowdown; just check at the "something else" point.

Otherwise, the easiest architectural tweaks would be:
-add a single enemy of another type and you have to keep that one alive. This may not be preferable due to specific enemy properties or movement, though.
-add a specific place to lead the last enemy to. Award the challenge when the enemy is on that tile, the other thing hasn't been done yet, and there are no other enemies in the room. Since you know where the last enemy has to go, it's easy to check that every other tile is enemy-free.
08-25-2016 at 04:46 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Insoluble
Level: Smitemaster
Avatar
Rank Points: 1638
Registered: 09-04-2014
IP: Logged
icon Re: Scripting Question: counting enemies? (+1)  
Dragon Fogel wrote:
Possible-but-tedious: check every individual tile that the enemy can step on and increment a variable for each of them you find.
This shouldn't be tedious to script at all. You can use nested loops. Have one loop check for enemies in each square of a row by incrementing _MyScriptX and have the other loop run the first one for every row on the screen by incrementing _MyScriptY. Since you really care about ensuring that there is exactly one enemy left, you don't actually have to count them. Just run the nested loops, and once the variable has gotten to 2 or more you can immediately exit the loops for that turn. That should cut back on any slow down at least (though I really don't think there will be all that much.)

____________________________
Links to neat forum tools that I always have trouble finding:
Click here to view the secret text

08-25-2016 at 05:30 PM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
robin
Level: Smitemaster
Avatar
Rank Points: 842
Registered: 09-01-2004
IP: Logged
icon Re: Scripting Question: counting enemies? (0)  
I have such a script. When I'm home, I'll post it here.

____________________________
Click here to view the secret text

08-25-2016 at 07:53 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
robin
Level: Smitemaster
Avatar
Rank Points: 842
Registered: 09-01-2004
IP: Logged
icon Re: Scripting Question: counting enemies? (+2)  
robin wrote:
I have such a script. When I'm home, I'll post it here.

http://forum.caravelgames.com/viewtopic.php?TopicID=40149&page=0#399086

Look what I found :D

____________________________
Click here to view the secret text

08-25-2016 at 08:55 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
Jacob
Level: Smitemaster
Rank Points: 3746
Registered: 10-01-2004
IP: Logged
icon Re: Scripting Question: counting enemies? (+1)  
What about something like this:
Start with a variable = number of monsters, defined by the architect
Subtract 1 each time monster killed
When you go to do something else (e.g. step on a certain tile):
if variable =1, fine (open a door or whatever). if variable != 1 then fail (close a door?).

Of course, this depends on there being no other monsters in the room that you could kill to decrement the variable, and depends on what exactly you want to happen specifically.


Edit: of course, this also disregards monster type, so forget it.

____________________________
New to DROD? You may want to read this.
My Holds and Levels:
Click here to view the secret text


[Last edited by Jacob at 09-02-2016 05:27 PM]
09-02-2016 at 05:26 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mauvebutterfly
Level: Smitemaster
Avatar
Rank Points: 720
Registered: 05-03-2015
IP: Logged
icon Re: Scripting Question: counting enemies? (+1)  
I know this is a few months late, but thanks everybody for helping out with this. I have it implemented now and I think it's working properly.

Making relatively good progress on the hold, so you guys might even get to see the room in a year or so ;)

____________________________
106th Skywatcher
11-27-2016 at 09:14 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
GerAvos
Level: Delver
Rank Points: 51
Registered: 05-28-2016
IP: Logged
icon Re: Scripting Question: counting enemies? (0)  
mauvebutterfly wrote:
I know this is a few months late, but thanks everybody for helping out with this. I have it implemented now and I think it's working properly.

Making relatively good progress on the hold, so you guys might even get to see the room in a year or so ;)
Cool dude, looking forward to your hold and many others!
12-26-2016 at 11:56 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Architecture : Scripting Question: counting enemies?
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.