Old 11-16-2018, 10:19 PM   #1
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 70
Default Is it a bad habit that setting the table index start from 0

I just realized that in the table.remove(tablename, index) function, the parameter "index" can't be 0, or you will get a warn messsage.

So I can't remove the table[0] via table.remove function
dsyrock is offline   Reply With Quote
Old 11-16-2018, 10:51 PM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,208
Default

It is for natural number indexes in the table which behaves as a massive.
If you want to simply remove table entry, use your_table[0]= nil
__________________
SoundCloud | MPL Scripts discussion | ReaPack | Donate
mpl is offline   Reply With Quote
Old 11-16-2018, 11:33 PM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,238
Default

Well, you find the answer to your own questions ^^ Yes, using index 0 in lua table is bad practice cause every table native functions and iterators expect them to start at index 1.
X-Raym is offline   Reply With Quote
Old 11-16-2018, 11:51 PM   #4
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 70
Default

I see. Thanks mpl and X-Raym
dsyrock is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.