If I add a table.insert() or a table.remove() within this if else statement, then my game crashes when down == true. I don't know why this is happening and I can't find a workaround for it either.if down == true then
if checkForPiece(chessPieceData, chessPieceMouseX, chessPieceMouseY) and (waiting == false) then
pieceIndex = findPieceIndex(chessPieceData, chessPieceMouseX, chessPieceMouseY)
waiting = true
print(pieceIndex)
else
table = chessPieceData[pieceIndex]
chessPiece = table[1]
waiting = false
end
end
My project crashes every time I try to edit the contents of a table in an if else statement.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Mon Jul 31, 2023 2:47 am
My project crashes every time I try to edit the contents of a table in an if else statement.
Re: My project crashes every time I try to edit the contents of a table in an if else statement.
table.insert and table.remove must be called when table is the original lua library, "table". You've assigned a variable with the same name, so lua expects to find a method called insert or remove, which you presumably don't have.novajourney wrote: ↑Mon Jul 31, 2023 2:49 amIf I add a table.insert() or a table.remove() within this if else statement, then my game crashes when down == true. I don't know why this is happening and I can't find a workaround for it either.
If you change table to a different variable name (e.g. tab), you'll be able to call table.insert(tab, x) normally.
Re: My project crashes every time I try to edit the contents of a table in an if else statement.
^ This.
"table" is a reserved word (kind of) so just rename that variable name.
"table" is a reserved word (kind of) so just rename that variable name.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Re: My project crashes every time I try to edit the contents of a table in an if else statement.
Also consider using [ code ] tags when posting on the forum:
novajourney wrote: ↑Mon Jul 31, 2023 2:49 amIf I add a table.insert() or a table.remove() within this if else statement, then my game crashes when down == true. I don't know why this is happening and I can't find a workaround for it either.Code: Select all
if down == true then if checkForPiece(chessPieceData, chessPieceMouseX, chessPieceMouseY) and (waiting == false) then pieceIndex = findPieceIndex(chessPieceData, chessPieceMouseX, chessPieceMouseY) waiting = true print(pieceIndex) else table = chessPieceData[pieceIndex] chessPiece = table[1] waiting = false end end
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Re: My project crashes every time I try to edit the contents of a table in an if else statement.
Just another example of the harm that globals can do.
Had 'table' been a local variable, that would not have happened.
Had 'table' been a local variable, that would not have happened.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 5 guests