So, I wrote a quick function that can run through all of my defined items until it detects a nonexistent one and write the last defined item ID into a global variable for use with a for/do block (or whatever may need that information to work efficiently). This script should work with almost any series of objects defined in your HSI file (items, songs, enemies, etc.) if you want a contained loop that counts every existing ID without going over the defined limit.
Code: Select all
global variable (1,itemcapped)
#example object limit finder (specifically for items)
#best to run at the start of your game or loaded game
script,find last defined item,begin
variable (loop)
loop := true
itemcapped := 0 #this variable will be used to close any conditional range of items used in a for/do block
while (loop) do(
clear string (1)
clear string (2) #second string MUST be zero
get item name (1,itemcapped) #writes HSI name for item ID that matches the value of "itemcapped" to string 1
if (string compare (1,2)==false) then( #basically checks whether string 1 has a name or returns zero
increment (itemcapped,1) #and increments the value of "itemcapped" if a name is found
)
if (string compare (1,2)) then( #breaks loop once both strings match, meaning string 1 has no name and returns zero
loop := false
)
)
clear string (1)
end
#example script that uses newly defined limit
script,inventory cleaner,begin
variable (i,inv)
for (i,0,itemcapped) do(
inv := inventory (i) #checks if the current item ID in the loop exists in player's inventory
delete item (i,inv) #and deletes it if found
)
end
#If game file has 302 items defined, then "itemcapped" will return a value of 302 if these scripts are written correctly.
Hope some of you will find this useful tonight. Odds are TMC will find a way to make it obsolete by tomorrow.