Forum

> > CS2D > Scripts > attempt to concatenate field '?'
Forums overviewCS2D overview Scripts overviewLog in to reply

English attempt to concatenate field '?'

7 replies
To the start Previous 1 Next To the start

old attempt to concatenate field '?'

_oops
User Off Offline

Quote
hello, i was making the script name "Jamming weapons"
while players shooting primary or secondary weapon, weapons will be jammed in rare case.
when weapons jammed, player's ammo will saved at temporary variables, remove player's weapon's ammo values. and then when player unjams it, temporary variable will replace empty ammo.

the error appears at line 50
1
LUA ERROR: sys/lua/jam.lua:50: attempt to concatenate field '?' (a boolean value)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function array(g,r)
	local a={}
	for i=1,g do
		a[i]=r
	end
	return a
end

jammy={}
jammy.user=array(32,0)
jammy.tempam=array(32,0)
jammy.tempamin=array(32,0)

addhook("attack","jammy.atk")
function jammy.atk(id)
wep = player(id,"weapontype")
	if (wep>=1 and wep<=49) then
	jamrandom=math.random(1,5) 
		if (jamrandom==1) then
		parse("sv_sound2 "..id.." \"env/click2.wav\"")
		parse("effect \"smoke\" "..player(id,"x").." "..player(id,"y").." 20 0")
		parse("effect \"fire\" "..player(id,"x").." "..player(id,"y").." 1 0")
		parse("explosion "..player(id,"x").." "..player(id,"y").." 15 3 0")
		parse("setammo "..id.." "..wep.." 0 0")
		timer(500,"parse","strip "..id.." "..wep.."")
		elseif (jamrandom==2) then
		jammy.user[id]=1
		jammy.tempam[id]=item(id,"ammo") -- save player's weapon's ammo value at "temporary variable"
		jammy.tempamin[id]=item(id,"ammoin")
		parse("setammo "..id.." "..wep.." 0 0")
		hudm(id)
		end
	end
end


function hudm(id)
parse("hudtxt2 "..id.." 5 \"\169230230230Press [E] to Unjam\" -120 84")
parse("hudtxtalphafade "..id.." 5 1 0.0")
parse("hudtxtmove "..id.." 5 500 30 84")
parse("hudtxtalphafade "..id.." 5 1000 1.0")
end

addhook("use","jammy.use")
function jammy.use(id,e)
	if e==0 then
		if jammy.user[id]==1 then
		parse("sv_sound2 "..id.." \"env/click2.wav\"")
		wep = player(id,"weapontype")
		  parse("setammo "..id.." "..wep.." "..jammy.tempamin[id].." "..jammy.tempam[id]) -- Error appears at this line
		parse("sv_sound2 "..id.." \"Oops321/Weapon/unjammed.ogg\"")
		jammy.user[id]=0
		parse("hudtxtalphafade "..id.." 5 3000 0.0")
		end
	end
end
	
function jamre(id)
wep = player(id,"weapontype")
parse("setammo "..id.." "..wep.." "..jammy.tempamin[id].." "..jammy.tempam[id])
parse("sv_sound2 "..id.." \"Oops321/Weapon/unjammed.ogg\"")
jammy.user[id]=0
parse("hudtxtalphafade "..id.." 5 3000 0.0")
end

thanks for read , sorry for bad english.

old Re: attempt to concatenate field '?'

DC
Admin Off Offline

Quote
At least one of the variables id, wep, jammy.tempamin[id] and jammy.tempam[id] is a boolean value (true / false). You can't concatenate such values with the ..-operator.

old Re: attempt to concatenate field '?'

Starkkz
Moderator Off Offline

Quote
@user _oops: use tostring.
1
2
tostring(jammy.tempamin[id])
tostring(jammy.tempam[id])
tostring converts any type of value into a string type. Note that it returns the new string.

old Re: attempt to concatenate field '?'

_oops
User Off Offline

Quote
@user Starkkz:
wonder i am doing right or not.
1
parse("setammo "..id.." "..wep.." "..tostring(jammy.tempamin[id]).." "..tostring(jammy.tempam[id]))

it works! but temp variables didn't replace ammo.

old Re: attempt to concatenate field '?'

DC
Admin Off Offline

Quote
The initial error message indicated the there was a boolean saved in the table. cs2d cmd setammo doesn't expect any booleans as parameter. So tostring doesn't solve the actual problem. The actual problem is that the variables contain the wrong values.

The problems is probably caused by using cs2d lua cmd item (with the parameters "ammo"/"ammoin") on items which do not exist (which will return false). You are having an ID variable but you're using it as player ID AND as item ID... which are two different types of IDs and which must lead to problems.

In other words: cs2d lua cmd item does NOT expect the ID of a player as first parameter. It expects the ID of an item on the ground as first parameter! That's your problem right now.
edited 1×, last 30.09.14 12:57:39 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview