Be a Supporter!

Need help with variables.

  • 395 Views
  • 8 Replies
New Topic Respond to this Topic
uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Need help with variables. 2007-02-01 20:41:28 Reply

on (release) {
if(_root.gun==0 && money>=500 && tired<=50){
robvar=Math.ceil(Math.random()*6) ;
if (robvar==1){
_root.money +=random(5000)
if(_root.gun==0 && money>=500 && tired<=50){
robvar=Math.ceil(Math.random()*6) ;
if (robvar==1){
_root.money +=random(5000)
tired +=50
gotoAndStop (2);
}
if (robvar==2){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(3);
}
if (robvar==3){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(4);
}
if (robvar==4){
gotoAndStop(5);
}
if (robvar==5){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(6);
}
if (robvar==6){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(7);
}
}
}
}
else if (_root.gun==1 && money>=500 && tired<=50) {
robvar=Math.ceil(Math.random()*3) ;
if (robvar==1){
_root.money +=random(5000)
tired +=50
gotoAndStop (8);
}
if (robvar==2){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(9);
}
if (robvar==3){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(10);
}
}
else if (_root.money<=500) {
gotoAndStop(11);
}
else if (_root.tired>50) {
gotoAndStop(12);
}
}

That's supposed to make it so that you have to have under 50 "tired" and over 500 "money." If you have 1 gun, it's supposed to give you better odds.

What it does is pretty much just go off on its own thing. Any suggestions?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Need help with variables. 2007-02-01 21:41:51 Reply

Come on, anyone?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
deltatsunami
deltatsunami
  • Member since: Dec. 31, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Need help with variables. 2007-02-01 21:49:56 Reply

wow, your code is so messy. Why don't you use switch...case statements.

Tell us more specifically what you want to accomplish and then we'll (or at leats I'll ) help.

uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Need help with variables. 2007-02-01 21:55:57 Reply

Okay, in the game, I want the player to have the option to rob a bank. When you try it without 1 of the "gun" variable, I want 6 random numbers to be generated, all going to a different scene inside the movieclip and taking away/adding to variables. To do this, I want the player to need at least 500 "money" and energy to be less than or equal to 50. I want four of these five tries to take away 500 from the "money" variable and add 15 to the "day" variable. I want one of them to just add 50 to the "tired" variable, and one to add a random number between 1 and 5,000 to the "money" variable.

If you try to rob it with 1 of the "gun" variable, I want the player to have one possibility to get the random number between 1 and 5,000 to "money" and two chances to take away 500 from the "money" variable and add 15 to the "day."

Help?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
Kart-Man
Kart-Man
  • Member since: Jan. 7, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to Need help with variables. 2007-02-01 22:01:54 Reply

At 2/1/07 08:41 PM, uyersuyer wrote: code

Er... I'm confuzzled. That is confusing code. I agree with deltatsunami and just use switch case statements. ie:

if (active == true) {
switch (option) {
case 1 :
_root.movement(moveX, moveY, this);
break;

Actually, I took that from the AS War code. :D

Research switch case stuff.


postcount +=1;
Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!
SING US A SING YOU'RE THE PIANO MAN

BBS Signature
uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Need help with variables. 2007-02-02 14:59:34 Reply

I don't understand the switch case thing and I can't find any tutorials. Anybody wanna try to explain?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Need help with variables. 2007-02-02 15:04:29 Reply

There aren't many tutorials because it's well explained in the language reference. Hit f1 some?


BBS Signature
uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Need help with variables. 2007-02-02 16:50:12 Reply

on (release) {
if (_root.gun==0 && money>=500 && tired<=50){
robvar=Math.ceil(Math.random()*6) ;
if (robvar==1){
_root.money +=random(5000)
tired +=50
gotoAndStop (2);
}
if (robvar==2){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(3);
}
if (robvar==3){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(4);
}
if (robvar==4){
gotoAndStop(5);
}
if (robvar==5){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(6);
}
if (robvar==6){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(7);
}
}
else if (_root.gun==1 && money>=500 && tired<=50) {
robvar=Math.ceil(Math.random()*3) ;
if (robvar==1){
_root.money +=random(5000)
tired +=50
gotoAndStop (8);
}
}
if (robvar==2){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(9);
}
if (robvar==3){
_root.money -=500
_root.day += 15
tired +=50
gotoAndStop(10);
}
else if (_root.money<=500) {
gotoAndStop(11);
day -= 30;
}
else if (_root.tired>50) {
gotoAndStop(12);
day -= 30;
}
}

I didn't really completely understand switch case so I tried just reworking my original AS and now it works BETTER but not perfect. Any tips?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature
uyersuyer
uyersuyer
  • Member since: May. 15, 2002
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Need help with variables. 2007-02-02 17:19:55 Reply

Anybody?


"Whoever said 'winners never quit' obviously never considered addicts." - Hoeloe

BBS Signature