Creating text to pop up with if(s) and then(s)
( [B][U]PLEASE disregard the default darkrp hud, I have no idea how to get rid of it when i'm in singleplayer, i'm so sorry[/U][/B]:cry: )
I've created this if statement to create text.
[CODE]if health == 20 or health < 20 then
draw.SimpleText("Critically Injured","font3",105,ScrH() - 80.5,Color(255,120,120, 225),1,1)
end[/CODE]
Correct me if I'm wrong, this states that if their health is equal to 20, or their health is less than 20 then "create a text saying critically injured".
[IMG]http://i.imgur.com/rKWX3Dg.png[/IMG]
So I advanced further because I saw that when I die, the text still remains when you die
[IMG]http://i.imgur.com/xH9pd93.png[/IMG]
So I wanted to get rid of that and I created the following
[CODE]if health == 20 or health < 20 and health > 20 then
draw.SimpleText("Critically Injured","font3",105,ScrH() - 80.5,Color(255,120,120, 225),1,1)
end[/CODE]
I added [B]and health > 20 then[/B], and I was like okay, this should make the text disappear when you die.
[B]And it did;[/B]
[IMG]http://i.imgur.com/64GQ3ax.png[/IMG]
[B]But only to find out this if statement does not make any sense?[/B]
I came to my senses and realised that [B]and health > 20 then[/B] is equal to "if health is greater than 20 then (create this text)"
but I simply tried to make it so the text would disappear when the person has died, e.g. when they reach 0 hp.
edit; or as the code would say ( only let it only pop up when it's in this bracket field " 20 hp and less, 0 hp and above " )
I don't know why that worked so I changed the code to
[CODE]if health == 20 or health < 20 and health > 0 then
draw.SimpleText("Critically Injured","font3",105,ScrH() - 80.5,Color(255,120,120, 225),1,1)
end[/CODE]
And they both work the exact same?
Can somebody please explain why?
[code]
if LocalPlayer():Alive() and health <= 20 then
...
end
[/code]
This will check if the player is alive and the health is less than (or equeal) to 20, then it'll do your desired function. Check the Lua docs for the operators ;)
the last code you wrote checked if the health is lower than 20, but higher than 0, EQ 1 it'll print your stuff, but its unoptimized/ugly.
[QUOTE=whitestar;51232444][code]
if LocalPlayer():Alive() and health >= 20 then
...
end
[/code]
This will check if the player is alive and the health is less than (or equeal) to 20, then it'll do your desired function. Check the Lua docs for the operators ;)
the last code you wrote checked if the health is lower than 20, but higher than 0, EQ 1 it'll print your stuff, but its unoptimized/ugly.[/QUOTE]
Still didn't answer my question, thanks for trying to help though.
use <= (less or equal)
[QUOTE=Klaes4Zaugen;51232465]use <= (less or equal)[/QUOTE]
-snip-
[QUOTE=whitestar;51232476]Thats more or equal.. Its basic math, duh..[/QUOTE]
[url]https://www.mathsisfun.com/equal-less-greater.html[/url]
Oh yeah.. my brain still aint working right, just slept 2 hours xD
I wanna dumbrate myself 1K times.
[code]if health == 20 or health < 20 and health > 20 then[/code]
This does not work dude. This statement is only true when your hp is [U]exactly[/U] 20 so obviously you wouldn't see the message when you're dead. But you won't see either when you have 19hp for example.
Basically this part:
[code]health < 20 and health > 20[/code]
always return false
I assume you only tested your code with 0hp and 20hp.
[QUOTE=pedrus24;51232614][code]if health == 20 or health < 20 and health > 20 then[/code]
This does not work dude. This statement is only true when your hp is [U]exactly[/U] 20 so obviously you wouldn't see the message when you're dead. But you won't see either when you have 19hp for example.
Basically this part:
[code]health < 20 and health > 20[/code]
always return false
I assume you only tested your code with 0hp and 20hp.[/QUOTE]
That's what I'm saying, it doesn't work yet it works how I wanted it to.
I used that code to make it so, when at 0hp it doesn't show, and it worked?
but yet it doesn't make sense because it conflicts with eachother.
I know it returns false, but why did it work how I wanted it to?
and no I tested it at 100hp, 21hp, below 0 and inbetween 20 with everycode i've sampled.
[B]1hp[/B]
[IMG]http://i.imgur.com/TTh6jks.png[/IMG]
[B]10hp[/B]
[IMG]http://i.imgur.com/IZLDv4L.png[/IMG]
[B]20hp[/B]
[IMG]http://i.imgur.com/O29BI1P.png[/IMG]
[B]21hp[/B]
[IMG]http://i.imgur.com/hcUg449.png[/IMG]
[B]100hp[/B]
[IMG]http://i.imgur.com/WUHMiAy.png[/IMG]
[B]0hp[/B]
[IMG]http://i.imgur.com/TBjRrpJ.png[/IMG]
[B]Code area[/B]
[IMG]http://i.imgur.com/Vl0g0mH.png[/IMG]
This if statement does not work, period. You have to look somewhere else to understand what's going on.
A few possibilities :
- The script is not reloaded correctly and somehow the working code is still running.
- You're editing the wrong file.
- This text is drawn by another portion of your code.
Isn't auto refresh disabled in darkrp because of simplerr or something? I remember people putting some comment at the beginning of their scripts so it reloaded correctly while using darkrp.
[QUOTE=bigdogmat;51232712]Isn't auto refresh disabled in darkrp because of simplerr or something? I remember people putting some comment at the beginning of their scripts so it reloaded correctly while using darkrp.[/QUOTE]
Autorefresh is working fine, it had also been added to linux. Do you use a paid server for developing? If so, look in the webpanel, some providers tick 'Disable auto refresh', NFO got that option.
[QUOTE=pedrus24;51232702]This if statement does not work, period. You have to look somewhere else to understand what's going on.
A few possibilities :
- The script is not reloaded correctly and somehow the working code is still running.
- You're editing the wrong file.
- This text is drawn by another portion of your code.[/QUOTE]
Well observed possibilities, however no.
They are not the cause, I can tell you right now that I am not editing the wrong file.
I reloaded the lua file and gmod, and ended up with same results.
Save the lua file like 10 times to make sure it loaded 'properly'.
[IMG]http://i.imgur.com/YO8CBGz.png[/IMG]
[IMG]http://i.imgur.com/strAA4O.png[/IMG]
[IMG]http://i.imgur.com/sFc9xNG.png[/IMG]
same results
[IMG]http://i.imgur.com/aLvGOXj.png[/IMG]
[IMG]http://i.imgur.com/vSqMfPy.png[/IMG]
[IMG]http://i.imgur.com/yNrlTV5.png[/IMG]
weird stuff.
You need to test with values between 0 and 20. like 15 etc..
[QUOTE=pedrus24;51232783]You need to test with values between 0 and 20. like 15 etc..[/QUOTE]
Genius!
[IMG]http://i.imgur.com/eGx70eK.png[/IMG]
[IMG]http://i.imgur.com/l1Bmqu4.png[/IMG]
[IMG]http://i.imgur.com/ZlIqVJ0.png[/IMG]
Perhaps it did not reload properly like it was supposed to.
If I left it on for a period of time would it just not reload whenever i save it?
And why is it, that this is its outcome?
First time I see someone so dedicated to make his own code not work :D
[QUOTE=lubatron;51232817]And why is it, that this is its outcome?[/QUOTE]
This behaviour has been explained in the thread.
[QUOTE=pedrus24;51232836]First time I see someone so dedicated to make his own code not work :D[/QUOTE]
xD
Never had any conflicts like this before.
so does this return as 'less than 20 and above 20 to not register?
and only to register as = to 20? simply because < 20 and > 20 conflict?
This part [B]health < 20 and health > 20[/B] is always false.
So we can simplify the original statement to [B]health == 20 or false[/B]
Which is the equivalent of [B]health == 20[/B].
So it only displays the text when the HP is equal 20.
[QUOTE=pedrus24;51232948]This part [B]health < 20 and health > 20[/B] is always false.
So we can simplify the original statement to [B]health == 20 or false[/B]
Which is the equivalent of [B]health == 20[/B].
So it only displays the text when the HP is equal 20.[/QUOTE]
Oh right, cheers.
It must've not reloaded properly after I changed the code from > 20 to > 0, and it'd just stay the same every time i reloaded it.
But yeah, LOL thanks for this.
Why use the long, unoptimized way, when you can use the small code I posted above..?
[QUOTE=whitestar;51232745]Autorefresh is working fine, it had also been added to linux. Do you use a paid server for developing? If so, look in the webpanel, some providers tick 'Disable auto refresh', NFO got that option.[/QUOTE]
Did you not read "Isn't auto refresh disabled in darkrp because of simplerr"? I know that auto refresh works normally
Sorry, you need to Log In to post a reply to this thread.