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.

RGSS doesn't allow decimals?

Status
Not open for further replies.
I'm making a minimap, and so that I can have any sized map I'm using this to work out a number to multiply things by:

Code:
wide = 119 / $game_map.width
    high = 82 / $game_map.height

The idea is, on a 100x100 sized map this should return:

wide = 1.19
high = 0.82

Then this will be multiplied by the player's x and y positions to make the co'ords to use for the player sprite on the minimap.

The problem is, RGSS always rounds these to a whole number for some reason.

Code:
p "#{wide}, #{high}"

Returns

"1, 0"

Is there any way I can do this?

Thanks in advance.
 
you can make it do decimals like this
wide = 119.0 / $game_map.width
adding the .0 at the end indicates it is a floating point operation.
Also, if you're only working with variable, you can convert to float like so
$game_map.width.to_f
Hope it helps
 
No worries. From what I know, most programming/scripting languages only use integers if you don't specify otherwise, mostly because the use of floating points is pretty rare in programming, it's not needed much.
 

e

Sponsor

That's not exactly true; most interpreted programming languages will use integer by default unless specified otherwise. And floating point arithmetic is pretty widely used, much more so than simple integers; the science community would collapse on itself without it, leaving a large, black hole of hate and disbelief.

I assume this has been solved, however.
 
Status
Not open for further replies.

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