Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Construed on Fri 17/02/2012 06:15:46

Title: structure help please[SOLVED]
Post by: Construed on Fri 17/02/2012 06:15:46
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...

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
???
Title: Re: structure help please
Post by: RickJ on Fri 17/02/2012 06:47:51
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 {
     }
}
Title: Re: structure help please
Post by: Construed on Fri 17/02/2012 06:59:47
Thanks for response.
Unfortunately with this code:

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 :(
Title: Re: structure help please
Post by: Khris on Fri 17/02/2012 09:06:40
You did use player.View with a capital V, right?

Also, I'd write
  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.
Title: Re: structure help please
Post by: Construed on Fri 17/02/2012 09:14:52
Aha!
Thank you both very much, It's a great sigh of relief to have that part over mostly :D
Title: Re: structure help please[SOLVED]
Post by: 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?
Title: Re: structure help please[SOLVED]
Post by: Construed on Fri 17/02/2012 11:47:07
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