Re: Need A Quick Fix

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...
for i = 0 to length(nesgames) do 
	if i >= 0 then 
		deleteItem(Game_List,nesgames[i]) --somewhere here causes it to crash 
	end if 
end for 

You can't subscript a sequence with zero! We count from one around here!

As Irv pointed out, according to the Win32Lib docs, deleteItem expects an item position, not an item value

There are actually several ways to skin this cat...

Pass -1 to the position parameter of deleteItem(), as Irv pointed out:

deleteItem( list, -1 ) 

Call eraseItems() which does the same thing:

eraseItems( list ) 

Walk backwards through the list, deleting each item as you go:

for index = getCount( list ) to 1 by -1 do 
	deleteItem( list, index ) 
end for 

Keep deleting the first item until the list is empty:

while getCount( list ) do 
	deleteItem( list, 1 ) 
end while 

I'll also point out that if you run a for loop where stop < start, the loop will simply exit. This is useful since you don't have to check getCount() > 0 first, just run for i = 1 to getCount() do and it will just exit if getCount() returns zero.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu