structure help please[SOLVED]

Started by Construed, Fri 17/02/2012 06:15:46

Previous topic - Next topic

Construed

Can anyone tell me how to properly structure this so the first part of the function wont use part of the second function or third function etc...
Code: ags

function chair_Interact()
{
if (player.view==42||16){

player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(60);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(16);
object[5].SetView(57);
RestoreWalkableArea(1); 

}



if (player.view==17||59){

player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(63);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(17);
object[5].SetView(57);
RestoreWalkableArea(1); 

}


if (player.view==18||58){

player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(64);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(18);
object[5].SetView(57);
RestoreWalkableArea(1); 

}

Damn thing is using part of the second function for the third and vise versa..although the first works fine...
Basically i need to know how it goes, like:

if
else
else if
???
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

RickJ

1. Post in Beginner forum
2. Indent code
3. Look at if-else in help

Quote
function chair_Interact() {
     if ((player.view==42)||(player.view==16)) {
     }
     else if ((player.view==17)||(player.view==59)) {
     }
     else if ((player.view==18)||(player.view==58)) {
     }
     else {
     }
}

Construed

Thanks for response.
Unfortunately with this code:
Code: ags

function chair_Interact(){
  
if ((player.view==42)||(player.view==16)) {
  
player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(60);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(16);
object[5].SetView(57);
RestoreWalkableArea(1); 

}



else if ((player.view==17)||(player.view==59)) {

player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(63);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(17);
object[5].SetView(57);
RestoreWalkableArea(1); 


}

else if ((player.view==18)||(player.view==58)) {

player.Walk(140, 160, eBlock);
object[5].SetView(47);
player.LockView(64);
player.Animate(0, 0, eOnce, eNoBlock, eForwards);
RemoveWalkableArea(1); 
object[0].Animate(1, 20, eOnce, eBlock);
object[0].SetView(14, 0, 1);
RestoreWalkableArea(1); 
cChar35.Walk(152, 151, eBlock);
RemoveWalkableArea(1); 
Display("I will bring you some food then!");
RestoreWalkableArea(1); 
cChar35.Walk(199, 92, eBlock);
RemoveWalkableArea(1);
cChar35.ChangeView(62);
cChar35.Walk(152, 151, eBlock);
RestoreWalkableArea(1);
RemoveWalkableArea(1);
Display("You are most welcome.");
cChar35.ChangeView(61);
cChar35.Walk(199, 92, eBlock);
Display("The food was delicous and restores your health.");
health += 50;
if (health > player_maxhealth) health = player_maxhealth;
player.ChangeView(18);
object[5].SetView(57);
RestoreWalkableArea(1); 

}
}


if ((player.view==42)||(player.view==16)) {
Doesn't work at all.
else if ((player.view==17)||(player.view==59)) {
Causes the second group to change the player into the first
and
else if ((player.view==18)||(player.view==58)) {
causes the third player to turn into the first :(
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

You did use player.View with a capital V, right?

Also, I'd write
Code: ags
  if (player.View == 42 || player.View == 16) {

Much more readable.

You are using the same code thrice although only a few numbers change. That's still not the way to do it.
What you do is set a few local variables, then use a single code block.

Also, you are removing a walkable area, then restoring it, with only a Display command in between.
Coding isn't like cooking, it's like building a watch.
Indent your code and clean it up, and people are much more likely to help you.

Construed

Aha!
Thank you both very much, It's a great sigh of relief to have that part over mostly :D
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Khris

I don't understand, using player.view doesn't even compile, but you're describing an in-game fault.
How did we fix this?

Construed

Quote from: Khris on Fri 17/02/2012 09:24:51
I don't understand, using player.view doesn't even compile, but you're describing an in-game fault.
How did we fix this?

it was the capital V
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk