Distance function problem

Non-platform specific questions.

Distance function problem

Postby mcavalcanti » Sat Jul 23, 2011 1:54 am

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);
}
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Distance function problem

Postby rykein » Sat Jul 23, 2011 9:57 am

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.
rykein
 
Posts: 63
Joined: Mon Jul 26, 2010 7:26 am
Score: 6 Give a positive score

Re: Distance function problem

Postby foleyjo » Sat Jul 23, 2011 11:02 am

Alternatively do a for loop that cycle through all the doors and then for each door check the distance
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Distance function problem

Postby mcavalcanti » Sat Jul 23, 2011 10:44 pm

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.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Distance function problem

Postby skydereign » Sun Jul 24, 2011 5:11 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Distance function problem

Postby mcavalcanti » Tue Jul 26, 2011 4:29 pm

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);
}
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Distance function problem

Postby mcavalcanti » Wed Jul 27, 2011 1:15 pm

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);
}}
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Distance function problem

Postby foleyjo » Wed Jul 27, 2011 5:53 pm

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.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Distance function problem

Postby mcavalcanti » Wed Jul 27, 2011 6:47 pm

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);
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Distance function problem

Postby skydereign » Wed Jul 27, 2011 8:01 pm

You have to use "door", not door.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Distance function problem

Postby mcavalcanti » Wed Jul 27, 2011 8:11 pm

Thanks too much!
Now its woking perfectly! =))

Best.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest