Forum

> > CS2D > Scripts > Table.insert depreciated/changed?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Table.insert depreciated/changed?

9 replies
To the start Previous 1 Next To the start

old Table.insert depreciated/changed?

Apache uwu
User Off Offline

Quote
http://lua-users.org/wiki/TablesTutorial seems to be outdated, because they show the syntax.

1
table.insert(table,value)

http://pgl.yoyo.org/luai/i/table.insert is the updated version of the function/method.

1
table.insert(table,[pos,],value)

I realized that when I was testing my scripts:

1
LUA ERROR: sys/lua/server.lua:1: bad argument #2 to 'insert' (number expected, got string)

That really sucks because my previous scripts are going to malfunction now.

What's odd is that the change seemed to happen overnight (it worked yesterday)...

Just though I'd let the scripting community know what just happened. √

old Re: Table.insert depreciated/changed?

DC
Admin Off Offline

Quote
user Apache uwu has written
What's odd is that the change seemed to happen overnight (it worked yesterday)...

that can't be true because that would mean that CS2D secretly updates its Lua components which is definitely NOT the case.

old Re: Table.insert depreciated/changed?

Apache uwu
User Off Offline

Quote
Im still wondering why this doesn't work

1
2
3
4
5
6
7
8
9
10
11
function myFunction(...)
	for _,item in ipairs(arg) do
		if item:trim()~="" then
			table.insert(tmp,item:trim())
		end
	end
end

function string:trim()
	return self:gsub("^%s*(.-)%s*$", "%0")
end

It only works when I use it like this.

1
2
3
4
tmp2=item:trim()
	if tmp2~="" then
		table.insert(tmp,tmp2)
	end

old Re: Table.insert depreciated/changed?

Deafcon1
User Off Offline

Quote
user Apache uwu has written
Im still wondering why this doesn't work

1
2
3
4
5
6
7
8
9
10
11
function myFunction(...)
	for _,item in ipairs(arg) do
		if item:trim()~="" then
			table.insert(tmp,item:trim())
		end
	end
end

function string:trim()
	return self:gsub("^%s*(.-)%s*$", "%0")
end

It only works when I use it like this.

1
2
3
4
tmp2=item:trim()
	if tmp2~="" then
		table.insert(tmp,tmp2)
	end


If it works, why do you complain?
In fact, your second code is better because it doesn't call the trim function twice.

by the way, this seems to run just fine...

1
2
3
4
5
6
7
8
9
10
function string.hello(self)
	return "hello "..self
end


a = "world"
tmp = {}
table.insert(tmp,a:hello())

print(unpack(tmp))

old Re: Table.insert depreciated/changed?

Apache uwu
User Off Offline

Quote
It is correct.

It just returns 2 values because of gsub, you would expect gsub to just replace --> and not tell you the location/section. That's really what string.find is for.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview