Hi everyone,
I'm currently working on a script for the player to press to show the level objectives on the screen like a HUD. Here I have chosen M is the key that the player has to press to show the objectives, and this is my script:
local openObj = 0
local showObj = 0
function objectives_init(e)
objOff = CreateSprite(LoadImage("scriptbank\\images\\zomteria\\hud\\showobjs.png"))
SetSpriteDepth(objOff,100)
blprint = CreateSprite(LoadImage("scriptbank\\zomteria\\training\\demo_blueprint.png"))
SetSpriteDepth(blprint,100)
objpaper = CreateSprite(LoadImage("scriptbank\\zomteria\\training\\demo_objectives.png"))
SetSpriteDepth(objpaper,100)
end
function objectives_main(e)
if openObj == 0 then
SetSpriteSize(objOff,7,-1)
SetSpriteOffset(objOff,15,-1)
SetSpritePosition(objOff,15,70)
SetSpritePosition(blprint,200,10)
SetSpritePosition(objpaper,200,10)
end
if g_Scancode == 50 and openObj == 0 then
PlaySound(e,0)
openObj = 1
if showObj == 0 then
SetSpritePosition(objOff,0,70)
SetSpriteSize(blprint,50,-1)
SetSpritePosition(blprint,5,10)
SetSpriteSize(objpaper,30,-1)
SetSpritePosition(objpaper,50,10)
showObj = 1
else
showObj = 0
SetSpritePosition(blprint,200,10)
SetSpritePosition(objpaper,200,10)
SetSpriteSize(objOff,7,-1)
SetSpriteOffset(objOff,15,-1)
SetSpritePosition(objOff,15,70)
end
end
if g_Scancode == 0 then
openObj = 0
end
end
The problem is that with this script, the player has to HOLD M to show the objectives, but I want to press to show it then press it again to close it. I have made a script like this:
if g_Scancode == 50 and openObj == 0 then
--This show the level objectives HUD
PlaySound(e,0)
openObj = 1
SetSpritePosition(objOff,0,70)
SetSpriteSize(blprint,50,-1)
SetSpritePosition(blprint,5,10)
SetSpriteSize(objpaper,30,-1)
SetSpritePosition(objpaper,50,10)
end
if g_Scancode == 50 and openObj == 1 then
--This close the level objectives HUD
SetSpritePosition(blprint,200,10)
SetSpritePosition(objpaper,200,10)
SetSpriteSize(objOff,7,-1)
SetSpriteOffset(objOff,15,-1)
SetSpritePosition(objOff,15,70)
openObj = 0
end
But it didn't work!
I want to press to show it then press it again to close it. Any ideas? Thanks in advance!
The author of this post has marked a post as an answer.
Go to answer