Forum

> > CS2D > Scripts > [Error] lua script
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [Error] lua script

8 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt [Error] lua script

DarkFireps2
User Off Offline

Zitieren
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)}

alt Re: [Error] lua script

Angel Montez
BANNED Off Offline

Zitieren
code

Spoiler >

alt Re: [Error] lua script

DarkFireps2
User Off Offline

Zitieren
user Angel Montez hat geschrieben
code

Spoiler >



The error continues

I think I have to define the variable id

alt Re: [Error] lua script

RIP-HereRestsPlookerbooy
BANNED Off Offline

Zitieren
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

alt Re: [Error] lua script

Angel Montez
BANNED Off Offline

Zitieren
good code sorry yes
Your program ran successfully.


Spoiler >
3× editiert, zuletzt 17.03.17 20:56:52

alt Re: [Error] lua script

Starkkz
Moderator Off Offline

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

alt Re: [Error] lua script

GeoB99
Moderator Off Offline

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