Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

display two variables as a fraction in a string?

I have a draw text command that goes like this:

draw_text(x+515,y+55,player_gun.magazine/player_base.ammo)

In my HUD object, it displays fine, but I can't figure out how to get it to actually display the two variables in the string the way I want. I want them to display like this:

50/100

but I get this:

0.50

basically, I want to negate the division and just display a slash between the two values. How would I do this?
 
that's what I thought, and I tried that.
___________________________________________
FATAL ERROR in
action number 12
of Draw Event
for object HUD_parent:

COMPILATION ERROR in code action
Error in code at line 4:
draw_text(x+515,y+55,player_gun.magazine"/"player_base.ammo)
^
at position 43: Symbol , or ) expected.
 

Jason

Awesome Bro

Hmm, see, I'm not too great with GML, so I'm just guessing lol.

How about...

draw_text(x+515,y+55,(player_gun.magazine+"/"+player_base.ammo))

Again, just guessing lol, not sure how to do this.
 
tried all of these (and more) and still nothing, so I got fed up with it and rewrote the code and changed it to display the two numbers as a fraction like this:

50
100

and I actually like it better this way so consider this solved :thumb:
 

Zeriab

Sponsor

I know you found another solution, but just fyi you can solve the problem by getting the string representation of the numbers and use standard string concatenation:
draw_text(x + 515, y + 55, player_gun.magazine.to_s + "/" + player_base.ammo.to_s)

*hugs*
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top