Jump to content

Recommended Posts

Posted

I'm wondering if anyone can tell me how to display the player health as a string as opposed to a number.

In my game, I'd like to have 4 stages of health.

Fine is between 75 and 100 health.
Injured is between 50 and 74 health.
Caution is between 25 and 49 health.
Critical is between 1 and 24 health.

For this I'm considering the following code which I am adding into the FPSplayer script:

if self.health >1 and <24 then hudText = "Critical" else
	if self.health >25 and <49 then hudtext = "Caution" else
		if self.health >50 and <74 then hudText = "Injured" else
			if self.health >74 and <100 then hudText = "Fine"
			end
		end
	end
end

local x = 0
local y = context:GetHeight() - fontHeight
context:DrawText(hudText, x, y)

I know I'm doing something wrong, and I'm sure there's probably a better way of doing this. But could anyone please help?

Posted

is this psuedo-code? or are you asking why it is not working?

if health>=1 and health <25 then 
	hudText = "Critical" 
elseif health>=25 and health<50 then 
	hudtext = "Caution" 
elseif health>=50 and health<75 then 
	hudText = "Injured" 
elseif health>=75 then 
	hudText = "Fine"
end

 

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted
3 minutes ago, Angelwolf said:

It's psuedo, sorry, should have mentioned. I re-wrote the entire post and managed to omit that part!

ok - and you also managed to omit what exactly the problem is... in your non-psuedo code, what exactly is it not doing? It would help if we knew that or saw the actual code.

Edit - ok see that the else/if/else if statements were the problem

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted
3 minutes ago, macklebee said:

is this psuedo-code? or are you asking why it is not working?


if health>=1 and health <25 then 
	hudText = "Critical" 
elseif health>=25 and health<50 then 
	hudtext = "Caution" 
elseif health>=50 and health<75 then 
	hudText = "Injured" 
elseif health>=75 then 
	hudText = "Fine"
end

 

This also works brilliantly, thank you.

Posted
Just now, macklebee said:

ok - and you also managed to omit what exactly the problem is... in your non-psuedo code, what exactly is it not doing? It would help if we knew that or saw the actual code.

There was no actual code at the time. I had tried a number of different ways of trying to achieve what I was looking for before I posted.
But despite this, you managed to give me something that worked right off the bat (with a few minor little changes).

From what I can tell, I was kind of close to working it out. Your code is a lot neater than mine, coding is definitely not a strong point of mine. I often know what I'm trying to do, but cannot quite seem to get it in the correct syntax.

  • Upvote 1
Posted
13 minutes ago, macklebee said:

Understand. I always refer to these sites when I want to double check anything lua:

http://pgl.yoyo.org/luai/i/_

http://www.lua.org/pil/contents.html

http://lua-users.org/wiki/LuaDirectory

Thank you for these, they do look a little intimidating though - but perhaps that's because I'm not too sure what I should have been looking for. I did try to look at the Leadwerks references but I didn't realise elseif was the correct syntax as opposed to else if.

But I'll know for next time!

Posted
14 hours ago, Thirsty Panther said:

Here is a couple of Youtube videos that I found helpful with Lua.

Aggror Project OLED

Brian Burton this one is not LW specific but he explains thing very well.

Thanks Panther!

I didn't know about the first link... the Project Saturn one has helped me out a number of times but this looks great too!

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...