English [Error] lua script

8 replies
Goto Page
To the start Previous 1 Next To the start
17.03.17 08:13:29 pm
Up
DarkFireps2
User
Offline Off
The error is :
Code:
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 :
Code:
1
extra_survivor.Image = {image("gfx/player/ct4.bmp",1,0,200+id)}
17.03.17 08:23:29 pm
Up
Angel Montez
BANNED
Offline Off
code

Spoiler >
CS2D playing pls!
17.03.17 08:24:52 pm
Up
DarkFireps2
User
Offline Off
user Angel Montez has written:
code

Spoiler >



The error continues

I think I have to define the variable id
17.03.17 08:39:43 pm
Up
Code:
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
17.03.17 08:44:01 pm
Up
Angel Montez
BANNED
Offline Off
good code sorry yes
Your program ran successfully.


Spoiler >
edited 3×, last 17.03.17 08:56:52 pm
CS2D playing pls!
17.03.17 08:56:29 pm
Up
Starkkz
Moderator
Offline Off
@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.
lol
17.03.17 08:57:14 pm
Up
DarkFireps2
User
Offline Off
@user Angel Montez:


I already fixed it, but the image does not come out


I put id=0
18.03.17 03:01:02 pm
Up
Borealis
Moderator
Offline Off
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.
Running CS2D in ReactOS like a boss | I'll be inactive for a couple of weeks. Sorry.
18.03.17 08:44:35 pm
Up
DarkFireps2
User
Offline Off
@user Borealis:
THX

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 rules §4.4 - Titles/texts in capital letters are impolite and undesired
To the start Previous 1 Next To the start