Page 1 of 1

Distance function problem

PostPosted: Sat Jul 23, 2011 1:54 am
by mcavalcanti
Hello. Please, I need help here. This script works really good on GED, but not on exported version.
When the user press space key AND hero distance from the door is smaller than 60 pixels, so play a door sound. Simple! But I detected that the distance function is not working on the exported version. May anyone help me?

Key down > Space > Script Editor:

if (distance(x,y,door.x,door.y)<60) {
PlaySound2("data/door.wav", 0.233333, 1, 0.000000);
}

Re: Distance function problem

PostPosted: Sat Jul 23, 2011 9:57 am
by rykein
problem is that door.x gets the door with the 0 cloneindex so if you have multiple doors it wont work right. i think a better way is to have a collision event that checks if space is pressed.

Re: Distance function problem

PostPosted: Sat Jul 23, 2011 11:02 am
by foleyjo
Alternatively do a for loop that cycle through all the doors and then for each door check the distance

Re: Distance function problem

PostPosted: Sat Jul 23, 2011 10:44 pm
by mcavalcanti
Hello, rykein. I don't need multiple doors. The problem is that the script is working good on GED, but not on the exported version. Anyway, thanks.

Re: Distance function problem

PostPosted: Sun Jul 24, 2011 5:11 am
by skydereign
rykein was talking about a known problem in exported games. If you have multiple door actors and you are using door.x then it is possible that it will mess up in exported versions. Using door.x will get the x position of the lowest indexed door clone, which may change when you export the game. That is one of the only reasons why you would experience a difference between the ged and the exported version.

Re: Distance function problem

PostPosted: Tue Jul 26, 2011 4:29 pm
by mcavalcanti
Oh, sorry. Now I understood.

Please, how can I put a For loop to check the door object and its clones? Thanks.

Key down > Space > Script Editor:
if (distance(x,y,door.x,door.y)<60) {
PlaySound2("data/door.wav", 0.233333, 1, 0.000000);
}

Re: Distance function problem

PostPosted: Wed Jul 27, 2011 1:15 pm
by mcavalcanti
Hi. Please, I need help here. I put a For loop, but it only works with door.0
It is not working with, for example, door.1 =(

Key Down >> Space:

int i;
for(i=0;i<5;i=i+1){
if (distance(x,y,getclone("door.i")->x,getclone("door.i")->y)<60) {
PlaySound2("data/door.wav", 0.233333, 1, 0.000000);
}}

Re: Distance function problem

PostPosted: Wed Jul 27, 2011 5:53 pm
by foleyjo
Firstly look up getclone2 in these forums and then add it to your global functions.

Then try the following code.

Code: Select all
Actor * ThisDoor;
int i;
for(i=0;i<5;i++)
{
  ThisDoor = getclone2(door,i);
  if (distance(x,y,ThisDoor->x,ThisDoor->y)<60)
  {
  PlaySound2("data/door.wav", 0.233333, 1, 0.000000);
  }
}


Not in the for statement I used i++. This is the same as i = i+1.

Re: Distance function problem

PostPosted: Wed Jul 27, 2011 6:47 pm
by mcavalcanti
Hello, foleyjo. Thanks for the reply. I followed your instructions. I added the clone2 code to the global functions and updated my script.

But I got this error:
Error: Incompatible types: cannot convert from 'struct' to '* char'

at this line:
ThisDoor = getclone2(door,i);

Re: Distance function problem

PostPosted: Wed Jul 27, 2011 8:01 pm
by skydereign
You have to use "door", not door.

Re: Distance function problem

PostPosted: Wed Jul 27, 2011 8:11 pm
by mcavalcanti
Thanks too much!
Now its woking perfectly! =))

Best.