|
|
|
|
Reply From: |
p7f |
Hi, I don’t know if i understood the question, but you want to compare to Time Survived + (Kill Count * 5)
instead of comparing to TimeSurvived
?
First of all, the way you are comparing text is not quite ok in my understanding. Because comparing strings will compare them alphabetically instead of numerically and (i asume) you need to compare numbers.
So, first get the numbers (idk if they are int or float in your case, but its similar. Also i asume you have already kill count number stored as an integer in var killcount
or something like that).
var score = int($Score.text)
var time = int($TimeSurvived.text)
then you get the number you want:
var num = time + killcount*5
Then you compare:
if score < num:
score = num
$Score.text = str(score)
Is that what you wanted?
Yes, this is what I was looking for. Thank you.
And, could you help me make the code better?
extends CanvasLayer
signal play_game
var score = int($Score.text)
var time = int($TimeSurvived.text)
var num = time + kill_count*5
func show_message(text):
$SystemMessage.text = text
$SystemMessage.show()
$MessageDuration.start()
func player_loss():
show_message("Game Over")
yield($MessageDuration, "timeout")
$Interactive/Button.show()
$SystemMessage.text = "New Game?"
$SystemMessage.show()
$Score.show()
if score < num:
score = num
$Score.text = str(score)
func score_count(score):
$TimeSurvived.text = str(score)
func _on_MessageDuration_timeout():
$SystemMessage.hide()
func _on_Button_pressed():
$Interactive/Button.hide()
$TimeSurvived.text = str("0")
$Score.hide()
emit_signal('play_game')
func kill_count(count):
$Kills.text = str(count)
System_Error | 2019-01-08 20:53
You are welcome!
What do you mean with “make the code better”? It looks ok to me…
Also, i think you should update num when you call player_loss, or in both functions where you update time and kills.
When I run my code, the debugger is complaining that an identifier isn’t found (kill_count).
System_Error | 2019-01-08 21:55
Because you dont have a variable called kill_count defined in your code. In the lin that you have this:
var num = time + kill_count*5
Change kill_count by int($Kills.text)
. I still think you should update num inside player_loss
before the comparation also.
Okay, how would I do that?
System_Error | 2019-01-08 23:52
try with this and tell me if it does not work:
extends CanvasLayer
signal play_game
var score = int($Score.text)
var time = int($TimeSurvived.text)
var kills= int($Kills.text)
var num = time + kills*5
func show_message(text):
$SystemMessage.text = text
$SystemMessage.show()
$MessageDuration.start()
func player_loss():
show_message("Game Over")
yield($MessageDuration, "timeout")
$Interactive/Button.show()
$SystemMessage.text = "New Game?"
$SystemMessage.show()
$Score.show()
num = time + kills*5
if score < num:
score = num
$Score.text = str(score)
func score_count(score):
$TimeSurvived.text = str(score)
time = score
func _on_MessageDuration_timeout():
$SystemMessage.hide()
func _on_Button_pressed():
$Interactive/Button.hide()
$TimeSurvived.text = str("0")
$Score.hide()
emit_signal('play_game')
func kill_count(count):
$Kills.text = str(count)
kills = count
Well, it was a bit messy. A friend helped get it done, though, and in a slightly cleaner way. We moved the majority of the stuff into Level.gd, so the HUD isn’t doing the calculations.
{HUDs are for showing data, and aren’t meant to do anything else.}
System_Error | 2019-01-10 03:57