GML [SOLVED] Image_Angle Issue

M

MechaZoid

Guest
Ok, so my problem is with the image angle variable. I'm creating a dungeon map generator that consists of a bunch of objects with random image indexes, and I'm trying to give them a random rotation (0, 90, 180, 270) every time i generate a new map. No errors show and the program runs fine, but the images wont rotate, no matter what i try.

(also I know there are other threads on this topic but I haven't found any that will fix my problem)

This is the step event for the map objects (global.changing and image_index = random(6) is part of the code for choosing a random image and works fine)

Code:
if (global.changing = true) {
    image_index = random(6)
    rot = random(3)
    if (rot = 0) image_angle = 0
    if (rot = 1) image_angle = 90
    if (rot = 2) image_angle = 180
    if (rot = 3) image_angle = 270
}
Thanks.
 

obscene

Member
random(3) will return a real number, like 2.57, so you'll never get an even 0,1,2 or 3. Use irandom(3) for an integer result.
 
Yeah, you'll need irandom. What I'd actually do is skip the checking part and just math it. Like this:

Code:
if (global.changing = true) {
   image_index = random(6)
   rot = irandom(3) * 90;
   }
 
M

MechaZoid

Guest
Thank you so much everybody, all answers were super helpful, final code looks like this for anybody who has this problem in the future:

Code:
 if (global.changing = true)
 {
    image_index = random(2)
    rot = irandom(3) * 90;
    image_angle = rot
 }
 
Top