Hood@
Let me see if I can help relieve your confusion.. I think most peoples problem so far is how LUA works with Reloaded..
This is the picture I have in my head when I was playing with the Door script - of how Lua works with Reloaded...
Inside Reloaded Lee has a loop that talks to each Entity. Using its Main LUA script.
So if we look at the Health script as an example.
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Player Collects Health
function health_find_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist < 80 then
PlaySound0(e);
AddPlayerHealth(e);
Destroy(e);
else
Prompt("Find the Health - distance to health is " .. PlayerDist);
end
end
1. You will see that I have renamed the script file health_find.lua
and the main function health_find_main
2. I have added an else to the PlayerDist if check.
The else portion of the code just shows the Prompt message on the screen with the players distance from the health entity ( healthbox ).
So I copy this new script health_find.lua to scriptbank folder.
I make a test level that only contains the start marker and the healthbox remote from the start maker.
I change the healthbox to use the helath_find.lua script inside reloaded editor properties dialog.( press Apply changes button )
Run the level.
You will see on the screen..
Find the Health - distance to health is 5045 (number depends on you level)
as I move around this number keeps changing - If I am going towards the health it gets smaller..
Now do you see You are already inside a loop (Lee's loop)..
If you put your play sound where the prompt is ... it would keep resetting the sound back to the beginning.
So we need an if statment something like
if PlayingSound0 == 0 then
PlaySound0(e);
end
but we don't have this PlayingSound0 variable from Lee yet...
anyway I hope this helps someone to see how LUA maybe working..
( I am just guessing - but that's the way it seems to work to me )