Okay, right off the bad, please do NOT point out crashes, bugs, or inefficient things unless they are DIRRECTLY related to the issue I'm having. I know where the crashes are. I will get to them later.
Anyhow, so I'm trying to delete object 2. But if there is a 3rd object there, it will ALWAYS delete the 3rd, even though I tell it to delete the 2nd.
How to reproduce:
Make three objects by puting the cursor in the positon then pressing p
Press D
Click deletemode
Press 2
Press enter
Wait
Then see that it deleted the object with the three above it.
Use the program I've attached in the post below and put the FOLDER named archive.love in your love folder.
Tables not working right
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Tables not working right
Sorry I couldn't upload it, but you can use pastebin
Steps:
Get the program from pastebin.com/Gwc5Zxme
Paste it into a file called main.lua
Zip main.lua
Call it Archive.love
Then get this:
http://www.sendspace.com/file/iq6x8v
Unzip it, then place the contents in your LOVE folder.
Thanks for helping.
Steps:
Get the program from pastebin.com/Gwc5Zxme
Paste it into a file called main.lua
Zip main.lua
Call it Archive.love
Then get this:
http://www.sendspace.com/file/iq6x8v
Unzip it, then place the contents in your LOVE folder.
Thanks for helping.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Tables not working right
I don't really recomend on using table.remove, use this instead:
Exemple usage:
EDIT: Don't worry that code wont go slow on large table, I managed to get 900+ FPS on a table of 800+ arrays, so it's good.
Why in hell's name don't you just post the love file, is it that hard ?
http://www.mediafire.com/download/7z6n6 ... elGUI.love
Guys use this file if you want to check out the OP's code ^
Code: Select all
for i=numbertodeletefromtable,#table do
table[i]=table[i+1]
end
Code: Select all
table={}
table[1]=1
table[2]=2
table[3]=3
for i=2,#table do
table[i]=table[i+1]
end
Why in hell's name don't you just post the love file, is it that hard ?
http://www.mediafire.com/download/7z6n6 ... elGUI.love
Guys use this file if you want to check out the OP's code ^
Re: Tables not working right
I had to upload the archive.love so you can actually run it
And what's the difference between the two?
Also, I really don't care about slowness. The program I'm using is meant to get a job done, but nothing else. Not to run fast or to look nice, etc. etc.
EDIT: I've changed the way it does it, now it gives me another error-- but it doesn't make any sence because I have set delNum to 2 yet it says it isn't a number. Help.(link, in love file: http://www.sendspace.com/file/0iugo5 )
Nevermind, I got it working. I just changed the variable name in a few spots but not all and it works fine now. And yes, I know, it's going to get slower and slower as I do that kind of stuff. It's okay.
And what's the difference between the two?
Also, I really don't care about slowness. The program I'm using is meant to get a job done, but nothing else. Not to run fast or to look nice, etc. etc.
EDIT: I've changed the way it does it, now it gives me another error-- but it doesn't make any sence because I have set delNum to 2 yet it says it isn't a number. Help.(link, in love file: http://www.sendspace.com/file/0iugo5 )
Nevermind, I got it working. I just changed the variable name in a few spots but not all and it works fine now. And yes, I know, it's going to get slower and slower as I do that kind of stuff. It's okay.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tables not working right
Whyyyyy? What reason can you possibly have to do that?Ranguna259 wrote:I don't really recomend on using table.remove, use this instead:
Help us help you: attach a .love.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Tables not working right
From here:Robin wrote:Whyyyyy? What reason can you possibly have to do that?Ranguna259 wrote:I don't really recomend on using table.remove, use this instead:
because it will move items several times when only one is needed. For instance if you remove every other entry in the array then a quadratic number of moves will be performed if you use table.remove
Re: Tables not working right
Your codeRanguna259 wrote:because it will move items several times when only one is needed. For instance if you remove every other entry in the array then a quadratic number of moves will be performed if you use table.remove
Does the same. It moves several items around. And if you need to keep the order in the array, then I don't see a simple way around (maybe you can leave gaps).Ranguna259 wrote:Code: Select all
for i=numbertodeletefromtable,#table do table[i]=table[i+1] end
If you don't care about the order, then you can replace the deleted entry by the last one.
Code: Select all
function remove(table,index)
table[index] = table[#table]
table[#table] = nil
end
Check out my blog on gamedev
Who is online
Users browsing this forum: Google [Bot] and 4 guests