English Death-screen script

4 replies
Goto Page
To the start Previous 1 Next To the start
10.11.13 06:09:54 pm
Up
D-D3ADxPro
User
Offline Off
By using this thread

http://unrealsoftware.de/forum_posts.php?post=361647#jn

I wanted to make a deathscreen script that will show a image when you are dead.

Heres the full code:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
deathscreen = {"gfx/minecraft_health/Death Screen/Deathscreen.png"}

addhook("die","deathscreen")
function deathscreen(id)
     if player(id, 'team') ~= 0 and player(id, 'health') > 0 then
     if healthimage[id] then freeimage(healthimage[id]) end
     deathscreen[id] = image("gfx/minecraft_health/Death Screen/Deathscreen.png",320,200,2,id)
     end
end

addhook("spawn","respawn")
function respawn(id)
     if deathscreen[id] then freeimage(deathscreen[id]) end
end


Line 208 is:
Code:
1
if deathscreen[id] then freeimage(deathscreen[id])


And then in console, it shows this
Code:
1
LUA ERROR: maps/as_mars.lua:208: attempt to index global 'deathscreen' (a function value)


Can anyone help?
10.11.13 06:14:08 pm
Up
Rainoth
Moderator
Offline Off
Yes. You have a function and a table named the same. When you call the table you get the function. The error says it quite obviously, Change table or function name.
10.11.13 10:22:01 pm
Up
MikuAuahDark
User
Offline Off
The deathscreen table should be this
Code:
1
deathscreen={}

then, add this to your code
Code:
1
2
3
4
5
6
7
for i=1,32 do deathscreen[i]=0 end

addhook("join","huh")
function huh(id)
     freeimage(deathscreen[id])
     deathscreen[id]=0
end

also, on hook cs2d lua hook die you shouldn't give the function name deathscreen because there is a table called deathscreen
edited 1×, last 11.11.13 06:49:11 am
file cs2d LuaJIT for Dedicated Server (13) JIT POWER! | Know your Lua errors! | Part of LÖVE development team since 11.3
11.11.13 03:11:25 am
Up
D-D3ADxPro
User
Offline Off
Code:
1
for i=1,32 do deathscreen[i]=0 end


Turns into this:

Code:
1
LUA ERROR: maps/as_mars.lua:198: attempt to index global 'deathscreen' (a nil value)
11.11.13 06:47:37 am
Up
MikuAuahDark
User
Offline Off
make sure that you put the loop code after
Code:
1
deathscreen={}
file cs2d LuaJIT for Dedicated Server (13) JIT POWER! | Know your Lua errors! | Part of LÖVE development team since 11.3
To the start Previous 1 Next To the start