The error is : 1
sys/lua/ZP/extraitems/survivor.lua:14: attempt to perform arithmetic on global 'id' (a table value)
The code is :Spoiler 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extra_survivor_id = ZP.CreateExtraItem("human")
extra_survivor = ZP.CFG.EXTRAHUMAN[extra_survivor_id]
extra_survivor.Cost = 1000
extra_survivor.Name = "Survivor (1 Round)"
id={id}
function extra_survivor.Equipable(id)
	return ZP_COUNT_DOWN > 0, "You may buy this item before the count down reaches zero"
end
function extra_survivor.Equip(id)
	PLAYER[id].MakeSurvivor()
end
extra_survivor.Image = {image("gfx/player/ct4.bmp",1,0,200+id)}
function extra_survivor.Spawn(id)
	if extra_survivor.Image[id] then
		freeimage(extra_survivor.Image[id])
		extra_survivor.Image[id] = nil
	end
end
The line of error code :
1
extra_survivor.Image = {image("gfx/player/ct4.bmp",1,0,200+id)}
code
Spoiler 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extra_survivor_id = ZP.CreateExtraItem("human")
extra_survivor = ZP.CFG.EXTRAHUMAN[extra_survivor_id]
extra_survivor.Cost = 1000
extra_survivor.Name = "Survivor (1 Round)"
id={id}
function extra_survivor.Equipable(id)
return ZP_COUNT_DOWN > 0, "You may buy this item before the count down reaches zero"
end
function extra_survivor.Equip(id)
PLAYER[id].MakeSurvivor()
end
extra_survivor.Image = image("gfx/player/ct4.bmp",1,0,200+id)
function extra_survivor.Spawn(id)
if extra_survivor.Image[id] then
freeimage(extra_survivor.Image[id])
extra_survivor.Image[id] = nil
end
end
Angel Montez has written
code
Spoiler 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extra_survivor_id = ZP.CreateExtraItem("human")
extra_survivor = ZP.CFG.EXTRAHUMAN[extra_survivor_id]
extra_survivor.Cost = 1000
extra_survivor.Name = "Survivor (1 Round)"
id={id}
function extra_survivor.Equipable(id)
return ZP_COUNT_DOWN > 0, "You may buy this item before the count down reaches zero"
end
function extra_survivor.Equip(id)
PLAYER[id].MakeSurvivor()
end
extra_survivor.Image = image("gfx/player/ct4.bmp",1,0,200+id)
function extra_survivor.Spawn(id)
if extra_survivor.Image[id] then
freeimage(extra_survivor.Image[id])
extra_survivor.Image[id] = nil
end
end
The error continues
I think I have to define the variable id 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
extra_survivor_id = ZP.CreateExtraItem("human")
extra_survivor = ZP.CFG.EXTRAHUMAN[extra_survivor_id]
extra_survivor.Cost = 1000
extra_survivor.Name = "Survivor (1 Round)"
for id = 1, 32 do
	extra_survivor.Image = image("gfx/player/ct4.bmp",1,0,200+id)
end
function extra_survivor.Equipable(id)
return ZP_COUNT_DOWN > 0, "You may buy this item before the count down reaches zero"
end
function extra_survivor.Equip(id)
PLAYER[id].MakeSurvivor()
end
function extra_survivor.Spawn(id)
if extra_survivor.Image[id] then
freeimage(extra_survivor.Image[id])
extra_survivor.Image[id] = nil
end
end
good code sorry yes
Your program ran successfully.
Spoiler 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
extra_survivor_id = ZP.CreateExtraItem("human")
extra_survivor = ZP.CFG.EXTRAHUMAN[extra_survivor_id]
extra_survivor.Cost = 1000
extra_survivor.Name = "Survivor (1 Round)"
id={id}
function extra_survivor.Equipable(id)
return ZP_COUNT_DOWN > 0, "You may buy this item before the count down reaches zero"
end
function extra_survivor.Equip(id)
PLAYER[id].MakeSurvivor()
end
addhook("spawn","extra_survivor_Spawn")
function extra_survivor_Spawn(id)
extra_survivor_Image = image("gfx/player/ct4.bmp",1,0,200+id)
if extra_survivor_Image[id] then
freeimage(extra_survivor_Image[id])
extra_survivor_Image[id] = nil
end
end
edited 3×, last 17.03.17 08:56:52 pm
@ Angel Montez: Using id={id}
is absolutely pointless because it creates a empty table (considering that 'id') is already nil in the global environment. @ Angel Montez:
I already fixed it, but the image does not come out
I put id=0 The bugged 14 line has a undeclared and undefined id
variable in the image function hence Lua thinks of it as global. Wrapping image("gfx/player/ct4.bmp",1,0,200+id)
with curly braces is a table which is pointless and unnecessary to do. And finally, "attempt to perform arithmetic" means a failed arithmetic operation on 200+id
because of the problem above.
Now considering you already fixed this issue but you're encountering another one (assuming by your last post), the image function line is put in the wrong place in Angel Montez's code. RIP-HereRestsPlookerbooy's code should work instead. Admin/mod comment
It's OK that you've got all the issues fixed. No need to use caps locks for the post though. /ZxC