Scripts / error with ? a nil value

Author
Message
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th May 2014 21:30 Edited at: 27th May 2014 21:47
can some1 tell me why this code produces 1 error







error running fuction: scriptbank\deathpoints.lua:18: attempt to index field '?' (a nil value)



and after closing this error it runs perfectly fine (does exactly as it's meant to)



i have narrowed it down to this part

Quote: "for a = 2, 9 do

checked[a] = 0

end"


but see no issue with it?



video of what it does



life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
RustyNuts
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 9th Nov 2011
Location: Warwickshire Great Britain
Posted: 27th May 2014 22:09
Hi smallg



now im no expert in LUA and im learning as i go.. but from what scripts i have played around with, this line
Quote: "error running fuction: scriptbank\deathpoints.lua:18: attempt to index field '?' (a nil value)"


indicates your error is on line 18.

All programmers are playwrights and all computers are lousy actors.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th May 2014 22:24 Edited at: 27th May 2014 22:29
indeed but if i remove the lines i quoted (which seem to be 4,5 & 6?) i get no error - however the points never go up



however i should have said that i do think the true error is in this line



Quote: "if g_Entity[enemy]['health'] < 1 then"


it doesnt seem to like the [enemy] part - maybe it thinks 1 of the entity numbers doesnt exist? i believe they should be 2,3,4,5,6,7,8,9

(i ran a script to check them in game first)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 28th May 2014 16:19
Hi smallg

I think you will find that you can not run code outside of a function...

The code outside your main function is only for declarations...

You need to put all code logic inside a function for it to run...

Hope this helps...
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th May 2014 00:12 Edited at: 30th May 2014 00:35
Quote: "Hi smallg

I think you will find that you can not run code outside of a function...

The code outside your main function is only for declarations...

You need to put all code logic inside a function for it to run...

Hope this helps..."




hmm i'm not sure about that, seems to work fine for stuff i don't need repeated at least



edit, removed the unneeded code and updated the varibles

anyway i fixed the error - just needed to add in a check for if enemy was nil or not





life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-12-22 05:36:16
Your offset time is: 2024-12-22 05:36:16