What's Wrong With This Code?


Goity

VIP Sleaze
Joined
Jun 22, 2004
Messages
5,598
Location
Isle of Ewe
Code:
arcade=rAND(0,5);  
If(arcade==1)
Enemyhpbar();
Enemy_id=Candice(140,120);
Return;
End
If(arcade==3)
Enemyhpbar();
Enemy_id=Enemy(140,120);
Return;
End
If(arcade==5)
Enemyhpbar();
Enemy_id=Netherbaby(140,120);
Return;
End
If(arcade==4)
Enemyhpbar();
Enemy_id=Supernanny(140,120);
Return;
End  
If(arcade==2)
Enemyhpbar();
Enemy_id=Somekid(140,120);
Return;
End

This always seems to return with the highest value, in this case five. How can I fix this?
 
You know, switch statements are made exactly for these situations. Translated:

Code:
switch(rand(0,5))
  case 1:
    Enemyhpbar();
    Enemy_id=Candice(140,120);
  end
  case 2:
    Enemyhpbar();
    Enemy_id=Supernanny(140,120);
  end
  case 3:
    Enemyhpbar();
    Enemy_id=Enemy(140,120);
  end
  case 4:
    Enemyhpbar();
    Enemy_id=Somekid(140,120);
  end
  case 5:
    Enemyhpbar();
    Enemy_id=Netherbaby(140,120);
  end
  default:
    //In case of another value, here only zero.
  end
  return;

I don't see how it can't work, have you tried doing it multiple times in one 'session'? It could be that it's just that the random seed isn't seeded(i.e. always returning values in the same order). Otherwise I do not see what is wrong with this code. Does it work on the PC?
 
1,3,5,4,2.... weird sequence.

anyways, are you sure the variable arcade is not always 5?
try to just display the variable and see if your "rAND(0, 5);" works...

edit: haha lol, was about to say something about the switch statement, but didnt knew if they existed on fenix :) .
 
check the rest of your code for something that sets it to the max value
Thats what I had the problem of in my game, when ever you hit a ball, it went rolling up and to the left or right, not straight

figured out I had put a wrong letter somewhere

~Octavious
 
I hope it`s not a seeding problem, cause that would render most to all of my minigames unplayable :(
 
I've sorted it by moving the rand to the main process. Quiest: Don't worry, this was on PC, so it isn't a GP2x bug.
 
I've also had problems with the 'rand' function, for me it was like in vb when you use that function, the program uses the same random pattern everytime, unless you tell it to randomize.
 
Back
Top