Forum

> > CS2D > Scripts > [Error] lua script
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Error] lua script

8 replies
To the start Previous 1 Next To the start

old [Error] lua script

DarkFireps2
User Off Offline

Quote
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 >


The line of error code :
1
extra_survivor.Image = {image("gfx/player/ct4.bmp",1,0,200+id)}

old Re: [Error] lua script

Angel Montez
BANNED Off Offline

Quote
code

Spoiler >

old Re: [Error] lua script

DarkFireps2
User Off Offline

Quote
user Angel Montez has written
code

Spoiler >



The error continues

I think I have to define the variable id

old Re: [Error] lua script

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
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

old Re: [Error] lua script

Angel Montez
BANNED Off Offline

Quote
good code sorry yes
Your program ran successfully.


Spoiler >
edited 3×, last 17.03.17 08:56:52 pm

old Re: [Error] lua script

Starkkz
Moderator Off Offline

Quote
@user Angel Montez: Using
id={id}
is absolutely pointless because it creates a empty table (considering that 'id') is already nil in the global environment.

old Re: [Error] lua script

GeoB99
Moderator Off Offline

Quote
The bugged 14 line has a undeclared and undefined
id
variable in the cs2d lua cmd 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 user Angel Montez's code. user RIP-HereRestsPlookerbooy's code should work instead.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview