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


Caravel Forum : DROD Boards : Architecture : Scripting Question: Checking every tile
New Topic New Poll Post Reply
Poster Message
mauvebutterfly
Level: Smitemaster
Avatar
Rank Points: 774
Registered: 05-03-2015
IP: Logged

File: Spider Killer.hold (1.3 KB)
Downloaded 49 times.
License: Public Domain
icon Scripting Question: Checking every tile (+2)  
This has been driving me crazy for a while, so I'm posting it here to try to get help. This script should check every single tile of the room, and if there's a spider, it removes the spider.

The idea was that this script could be thrown into a custom monster hold without needing to select the spider tile in each room individually.

However, there's a big problem with this script. It won't loop properly. _MyX is currently set to loop at 37, which misses the last column of the room. If I set it to loop at 38 instead, it hits the last column of row 0 but then aborts the script.

This doesn't seem like it should be a difficult script, so what simple thing am I overlooking here?

(Script in attached hold copied to secret comment for convenience)

Click here to view the secret text


____________________________
106th Skywatcher
07-05-2021 at 03:06 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Xindaris
Level: Smitemaster
Avatar
Rank Points: 1593
Registered: 06-13-2015
IP: Logged
icon Re: Scripting Question: Checking every tile (+2)  
Classic off-by-one error, gets everybody. The westmost row is the row with x = 0, so the eastmost row is the row with x = 37, not 38, so the script already gets the eastmost row. Just try putting a spider in the eastmost row and that script should locate it just fine.

Also, the script is probably aborting when you set MyScriptY to 32 for more or less the same reason. It only needs to go to 31.

____________________________
109th Skywatcher

Here are some links to Things!
Click here to view the secret text


[Last edited by Xindaris at 07-05-2021 04:10 AM]
07-05-2021 at 04:08 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
mauvebutterfly
Level: Smitemaster
Avatar
Rank Points: 774
Registered: 05-03-2015
IP: Logged

File: Spider Killer.hold (1.3 KB)
Downloaded 52 times.
License: Public Domain
icon Re: Scripting Question: Checking every tile (+2)  
I tested this script with spiders in all four corners. With _MyX at 37 it does not get the eastmost row. That's the point of confusion.

I don't believe that _MyY is causing any issues, since the bottom row does get cleared when the X variable is limited such that it's insufficient. It's possible the script is aborting after doing all the rows, but that doesn't affect the script's functionality itself if it does since it would still be covering everything.

Actually, looking at this again, I think I suddenly see the issue. Complain and solve at work in scripting too, I guess.

I wasn't updating _MyScriptX to be equal to _MyX due to the way the final column was being checked. The script works now.

Fixed script:
Click here to view the secret text


Apparently this issue has been sitting on my computer since October 29, 2019. Well, at least it's done now. I was really excited about this hold, so maybe I'll actually get some architecture done again soon.

____________________________
106th Skywatcher
07-05-2021 at 05:33 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
skell
Level: Legendary Smitemaster
Avatar
Rank Points: 3771
Registered: 12-28-2004
IP: Logged
icon Re: Scripting Question: Checking every tile (+2)  
Here is part of the script I have in my latest hold that iterates over the whole room doing things:

Click here to view the secret text


It's optimized for number of commands executed per checked tile, though not sure if it's perfectly optimized. Interestingly enough, using GoSub instead of GoTo could be marginally faster, but it would be more memory intensive. The reason is that GoTo on each execution goes through the list of all commands, trying to find the label. In this case, even if the body of the loop was big, it'd still be fast because the labels are near the start of the list. And on the other hand, GoSub might be slower because it'd have to build a stack of 1216 return points, and that would require a) a lot of memory and b) a lot of resizing the internal data structure.

____________________________
My website
07-06-2021 at 09:16 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts High Scores This architect's holds Quote Reply
mauvebutterfly
Level: Smitemaster
Avatar
Rank Points: 774
Registered: 05-03-2015
IP: Logged
icon Re: Scripting Question: Checking every tile (+2)  
Thanks skell. It's not necessary for my spider-killer script to be efficient since it only runs once at the start of the room, but I guess it's a good habit to get into. If I was making a custom element that checked every tile every turn, I'd be better off using your script as a starting point than mine then, right?

I'll probably also change the spider-killer to use your method as well.

____________________________
106th Skywatcher
07-07-2021 at 02:04 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
skell
Level: Legendary Smitemaster
Avatar
Rank Points: 3771
Registered: 12-28-2004
IP: Logged
icon Re: Scripting Question: Checking every tile (0)  
In case of one-time script it doesn't really matter much. It's more of an issue if you want to do a lot of things in a single script. And I'd argue the readability of my version is slightly better but I might be wrong here :).

And if you want to do some room-wide scan every turn then yea, better use the more optimal version for faster undo.

____________________________
My website
07-07-2021 at 11:54 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Architecture : Scripting Question: Checking every tile
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.