Page 1 of 1

Table field 1 not initialized

Posted: Thu Oct 12, 2023 8:26 pm
by amyren
Am I doing something wrong here or could this be a bug?

This code will quit with the following error:
Error in line 8 (Unnamed4.hws): Table field 2 was not initialized!

To reproduce, select and ban first user on the list, then do the same for the second user. Then select first user again and remove ban.

Code: Select all

bannedlist$ = {}
playerlist$ = {"Tom", "Peter", "Adrian"}
Repeat
If (ListItems(playerlist$) = 0) Then r = -1 Else r = ListRequest("Playerlist", "BAN player", playerlist$)
	receivername$ = playerlist$[r]	
	alreadybanned = False
	For i = 0 To ListItems(bannedlist$) -1
		If receivername$ = bannedlist$[i]
			alreadybanned = True
			sel = SystemRequest("Banned user", receivername$.." is already banned\nDo you want to remove the ban?", "Remove|Cancel")
			Switch sel
			Case 1:
				RemoveItem(bannedlist$, i)
			EndSwitch
		EndIf
	Next
	If alreadybanned = False
		InsertItem(bannedlist$, receivername$); add user to bannedlist
	EndIf
VWait()
Forever

Re: Table field 1 not initialized

Posted: Fri Oct 13, 2023 10:40 am
by amyren
Ok, sleeping on it helped:)
I see know why this error comes.
I am removing the table item while still in the FOR NEXT loop, so the next loop will throw the error.