Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dr Fred Rubacant Edison on Thu 30/11/2006 03:16:05

Title: Need help moving a object to one point and back have code
Post by: Dr Fred Rubacant Edison on Thu 30/11/2006 03:16:05

want to move a object to one point in the room and back to the same place it was when you click on it



// script for Object 1 (Poster): Look at object  // just experment
int pos1;
int pos2;


if (pos1==0) {
object[1].SetPosition(438, 111);
pos1=1;
}

 
if (pos1==1) {
object[1].SetPosition(379, 118);
pos1=0;
}

Title: Re: Need help moving a object to one point and back have code
Post by: Creator on Thu 30/11/2006 04:20:25
Try this:

// script for Object 1 (Poster): Look at object
int pos1;
int pos2;


if (pos1 == 0) {
object[1].SetPosition(438, 111);
}

 
if (pos1 == 1 ) {
object[1].SetPosition(379, 118);
}

if (pos1 < 1) {
  pos1 += 1;
}

if (pos1 == 1)
  pos1 == 0;
}

Title: Re: Need help moving a object to one point and back have code
Post by: Dr Fred Rubacant Edison on Thu 30/11/2006 04:52:55
the code Didnt work  :(

and this part of the code didnt compile  it said undefine sysmbol pos

if (pos 1 == 1)
  pos 1 == 0;
}
Title: Re: Need help moving a object to one point and back have code
Post by: Gilbert on Thu 30/11/2006 05:08:25
Didn't really look into whether the codes work or not, but:


if (pos1 == 1)
Ã,  pos1 = 0;
}

Remember: double '=' is for comparison while single '=' is for assignment, also no space is allowed in variable names.

Edit: Okay, just read your original post, your original codes should sorta work (not Creator's "workaround") , but with some ammendments:

Move the two variable declaration lines OUTSIDE of the "look at object" function, but move them to the top of that room's script instead (otherwise they'll be redeclared and reset whenever the interaction is run). The pos2 variable is not used in your poted codes though (unless it's to be used somewhere else). So:
int pos1=0;
int pos2=0;

Also:
// script for Object 1 (Poster): Look at objectÃ,  // just experment
if (pos1==0) {
object[1].SetPosition(438, 111);
pos1=1;
} else if (pos1==1) {
object[1].SetPosition(379, 118);
pos1=0;
}

(If you didn't add the 'else' the 'if (pos1==1)' part will always be executed)
Title: Re: Need help moving a object to one point and back have code
Post by: Creator on Thu 30/11/2006 05:12:59
Quote from: Gilbot V7000a on Thu 30/11/2006 05:08:25
pos1 = 0;

Yes, yes silly me sorry.
Title: Re: Need help moving a object to one point and back have code
Post by: Dr Fred Rubacant Edison on Thu 30/11/2006 21:54:47
Code worked thank you guys