Forum

> > CS2D > Scripts > Table.insert depreciated/changed?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Table.insert depreciated/changed?

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Table.insert depreciated/changed?

Apache uwu
User Off Offline

Zitieren
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. √

alt Re: Table.insert depreciated/changed?

DC
Admin Off Offline

Zitieren
user Apache uwu hat geschrieben
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.

alt Re: Table.insert depreciated/changed?

Apache uwu
User Off Offline

Zitieren
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

alt Re: Table.insert depreciated/changed?

Deafcon1
User Off Offline

Zitieren
user Apache uwu hat geschrieben
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))

alt Re: Table.insert depreciated/changed?

Apache uwu
User Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht