Forum

> > CS2D > Scripts > Mysterious nil callings (read first)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Mysterious nil callings (read first)

3 replies
To the start Previous 1 Next To the start

old Mysterious nil callings (read first)

EngiN33R
Moderator Off Offline

Quote
So, I've been fooling around with Lua, using movetile hook, and here is what I discovered - short problem description.

     - When walking, "attempt to call a nil value" error appears in the console.
     - When removing the hook, no errors appear.
     - When changing the functions inside the hook, error remains.
     - Renaming the function makes one more error appear (means now there are two same errors). Renaming the function further makes one more error appear, etc. I've got like 8 errors by now.

I don't have ANY idea what is this, but everything works fine, perfect, except for these damn errors.

The hook code and a function it calls:
1
2
3
4
5
6
7
8
9
10
11
12
13
function rconv(id,x,y)
    local rx=x-xfactor
    local ry=y-yfactor
    return 1+(3*(ry-1))+(rx-1)
end

addhook("movetile","rouletteconv")
function rouletteconv(id,x,y)
    if (player(id,"x")>=rsx and player(id,"x")<=rex and player(id,"y")>=rsy and player(id,"tily")<=rey) then
        roulettenumber[id]=rconv(id,x,y)
        hudtxt2(id,1,"255255255","Your roulette number is "..roulettenumber[id],250,25)
    end
end

I've had this problem before, and solved it, but, sadly, forgot the way to solve it. Has anyone else encountered that and how do I make the errors disappear?!

old Re: Mysterious nil callings (read first)

Banaan
User Off Offline

Quote
Have you declared the globals xfactor and yfactor?

Have you declared globals rsx, rex, rsy and rey?

Have you declared the function hudtxt2?

You might also want to try to create an empty table roulettenumber at the start of your script (roulettenumber={})

Furthermore, restarting your PC might help, as Lua sometimes gives mysterious 'nil value' errors for no reason, which can be solved by a pc restart.

old Re: Mysterious nil callings (read first)

Flacko
User Off Offline

Quote
Banaan has written
Furthermore, restarting your PC might help, as Lua sometimes gives mysterious 'nil value' errors for no reason, which can be solved by a pc restart.


I think that just closing CS2D should be enough to clear all the lua garbage data that might have not been correctly dealt with.
Atleast it worked like that in my case

old Re: Mysterious nil callings (read first)

Banaan
User Off Offline

Quote
There has been a thread about that on CS2DWorld:

http://cs2d.nl/index.php?mod=board&action=thread&where=92&start=0

leegao has written
CS2D doesn't clear the Lua call stack once you exit. Essentially, if you have anything on the __gc stack, the entire stack gets suspended when map-change occurs and resumes without checking for local and upvalue integrity. (This is a problem in the BlitzMax Lua module itself so it's most likely not possible to fix)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview