Leave room issues...

Started by AnasAbdin, Wed 17/08/2011 07:45:20

Previous topic - Next topic

AnasAbdin

sometimes ags makes me feel that I just can't code...

I have a room with two exits on the left.... a top and bottom doors that are aligned vertically... if the player exits the top one he should go to a room.. and the bottom goes to another room...

I used this kinda code in the leave room from the left edge as follows:

Code: ags
if ( player.y > 250 )
{
  player.changeRoom( room1, x, y);
}
if ( player.y < 250 )
{
  player.changeRoom( room2, x, y);
}


I tried this as well:

Code: ags
if ( player.y > 250 )
{
  player.changeRoom( room1, x, y);
}
else
{
  player.changeRoom( room2, x, y);
}


the code forces the player to exit to room1 all the time... I have tried:
Code: ags
if ( player.y > 250 )
{
  player.changeRoom( room1, x, y);
}
else
{
  return;
}


and it worked fine, he would exit from the top door only...

another thing.. many times I feel ags is not stable... specially with 'if' conditions as I mentioned above... maybe my head is not stable after all  :-\

one more thing... since I feel my 'if' conditions are 'neglected' sometimes.. how can I make sure they are forced to run repeatedly -say- every 1 or 2 seconds without causing too much load on the processing?

thanx

Bogdan

#1
There is a function you can use in every room. It's called if player leaves left edge, or if player leaves right edge or bottom or top. And you can set edges of the room too. Watch this tutorial it might help you: http://www.youtube.com/watch?v=FTZyDwGens0
You can also use regions instead(which solves your current problem) here is the link for the tutorial http://www.youtube.com/watch?v=azj9q9_VU1A

AnasAbdin

I am using edge functions to leave rooms... I was concerned with leaving to different rooms depending on the y coordinate of the player...

I did solve the issue with a region, but still, I need to understand why ags refuses to deal with it in the edge function..

Khris

Quote from: AnasAbdin on Wed 17/08/2011 07:45:20
the code forces the player to exit to room1 all the time... I have tried:
Code: ags
if ( player.y > 250 )
{
  player.changeRoom( room1, x, y);
}
else
{
  return;
}


and it worked fine, he would exit from the top door only...

Not sure why he would exit from the top door only when you're doing player.x > 250.

Quoteanother thing.. many times I feel ags is not stable... specially with 'if' conditions as I mentioned above... maybe my head is not stable after all  :-\

With this two options, it's definitely your head :=
Just kidding, but AGS does exactly what you tell it to do, all the time, every time. If you have the impression that sometimes commands are ignored arbitrarily, this is either a specific bug or a scripting/user error.

And for this reason:
Quoteone more thing... since I feel my 'if' conditions are 'neglected' sometimes.. how can I make sure they are forced to run repeatedly -say- every 1 or 2 seconds without causing too much load on the processing?

That's really wrong, all you need to do is fix the error.

What I would do is debugging 101:
Add this to the room script:

Code: ags
void on_key_press(eKeyCode k) {
  if (k == eKeySpace) Display("player.y = %d", player.y);
}


Now approach both doors and hit space to figure out the actual value of player.y in the vicinity of the doors.

AnasAbdin

Quote from: Khris on Wed 17/08/2011 11:42:52Now approach both doors and hit space to figure out the actual value of player.y in the vicinity of the doors.

y coordinates are perfectly as expected... the thing is I keep forgetting that I'm not using Borland Java builder or J-Creator.. u see in AGS' room scripts for example, variables should be initialized before the functions using them... that is not the way java classes deal with it  :-

thanx for the time to reply Khris, I'd also love to hear your opinion on my game as well :)
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44009.0

Khris

So what was the problem? Did you use variables in the ChangeRoom commands?

AnasAbdin

only the y coordinate of the player...
Code: ags
if ( player.y < 250 )


Khris

I don't get it. Did you solve this or not? What was the problem?
player.y isn't a variable that has to be initialized, is it?
What does this have to do with Java?

AnasAbdin

I already said I solved the problem using a region for one of the doors..
listen this is the whole thing:

I want the player to change room when he leaves from the left edge...
however, I wanted him to leave to room1 if his y < 250
and to room2 if his y > 250...

I coded it this way:
Code: ags
if ( player.y < 250 )
{
  player.changeRoom( room1, x, y);
}
else
{
 player.changeRoom( room2, x, y);
}


but he leaves to room1 either way.... I added a region near one of the exits so he would leave to room2 when he steps on it... it worked, but I was wondering why the leave_from_left wasn't working from the first place...

the java comparison is about initialization... you see in java it doesn't matter where you initialize variables in a class, but AGS has to have the variables initialized in the code before the functions using them...

Java:
Code: ags
int getNumber()
{
  return myNumber;
}

int myNumber = 0;


AGS:
Code: ags

int myNumber = 0;

int getNumber()
{
  return myNumber;
}


-=Lisa=-

Ok. im a noob here.. but...

player.changeRoom( room1, x, y);

shouldn't this be:

player.changeRoom( 1, x, y);

unless the "room1" variable is initialized to something else???

AnasAbdin

Quote from: -=Lisa=- on Thu 18/08/2011 10:59:35player.changeRoom( room1, x, y);

it's an example..

the real code is something like this:
Code: ags
player.changeRoom( 23, player.x, player.y);

Khris

Right.
I still don't have a clue why you even mentioned Java. I can't see how it relates to the problem in any way at all.

Now, I tested this by putting this in the room script:

Code: ags
function room_LeaveLeft()
{
  if (player.y < 150) Display("room 1");
  else Display("room 2");
  
  player.StopMoving();
  player.x = 20;
}


And exactly as I expected, the code works absolutely flawlessly.

That's why I wanted to know if you tried the debug approach where the game displays the current value of player.y. Even if your problem is solved, somebody else might discover this thread, having the same problem.

The only thing I can think of what caused the original problem is that your game is set to use lowres coordinates in script. So while your rooms are 400 (or 480) pixels high, that's 200 (240) internally, meaning that player.y will thus always be smaller than 250.

monkey0506

#12
I typed out quite the rant earlier and thanks to my stupid phone it completely failed to post and got obliterated forever. Thankfully Khris was actually able to get you to respond to one of his questions, regarding what you meant when you said "initialize variables in Java". It was of course total and complete utter bullocks, but you answered him at least.

I'm saying it's bullocks not because you're using the word "initialize" when what you mean is "define", but because player.y is defined (and automatically initialized, because AGS initializes all its variables with default values) via the Character struct of which player is a pointer-to-an-instance-of. The instances of the Character struct are all initialized before any of your rooms are ever loaded. So you saying that this issue had anything to do with your usage of player.y was just bullocks, plain and simple.

It's easy to just write things off (like how you said that if-statements must not work in AGS since you can't figure out how to debug your code properly) when you have absolutely no idea what you're doing. Not trying to be as rude as I'm sure I'm coming across here, but seriously, you've been directed in steps to take, and had information requested from you, and the most you've done is accuse AGS of being broken, and then come up with a solution which, regardless of whether it works, is actually completely unrelated to the original issue, which was in fact a user error.

Quote from: AnasAbdin on Wed 17/08/2011 20:15:46y coordinates are perfectly as expected...

@Khris: If this statement is indeed correct, then I doubt if he's turned off native-coordinates. Of course maybe he expected the coordinates to always be less than 240..who knows? ::)

Quote from: AnasAbdin on Wed 17/08/2011 20:15:46the thing is I keep forgetting that I'm not using Borland Java builder or J-Creator..you see in AGS' room scripts for example, variables should be initialized before the functions using them... that is not the way java classes deal with it  :-\

One more thing about this. If you were defining your own variables and you tried to reference them before they were defined, there are only two possible outcomes:

1) You would get a compile-time error: "Undefined token 'XXX'" where XXX is the name of the variable that you haven't defined yet.

2) If you had already imported said variable to try to make it global, and you reference it between the import and the definition of the variable, you would get a compile-time error: "Already referenced name as import"

That would make it kind of impossible for you to forget to define your variables before you use them. As I said, the only variable you've actually said that you were using is already defined before you even see anything happen in an AGS game.

Another way of using the Display function to debug this problem would have been to put a Display right in there with the ChangeRoom calls:

Code: ags
function room_LeaveLeft()
{
  if (player.y < 250)
  {
    Display("(1) player.y: %d", player.y);
    player.ChangeRoom(1);
  }
  else
  {
    Display("(2) player.y: %d", player.y);
    player.ChangeRoom(2);
  }
}


You could also have tried using break-points, or even the AbortGame function. The only indication you gave that you tried any type of debugging was your statement that the y-values were what you expected. Didn't say what they were (i.e., were they ever >250??)..didn't really give any elaboration at all. I've brought it up to you before that you need to give us more information about what's going wrong and what you're doing to try and fix it. Guess we see how well that went over.

AnasAbdin

Khris I'm so sorry if I mislead you in a way... I didn't mean to create a confusion between the leave_room issue and my java comparison thing...

I wasn't referring to this specific problem (leave_room) when I mentioned java... I was talking about positioning this line in the code:
Code: ags
int someInteger = 0;


you see, in java classes I can put this line outside the methods as:

Code: ags
class myClass{

void method1()
{
//do stuff
x = someInteger;
}

bool method2()
{
  if ( someInteger == 0 )
  {
    //do stuff
  }
}

int someInteger = 0;  //outside, middle of code and between methods...

int method3()
{
//do stuff
}

}  //end of class


however in AGS... when I add the following line in a room script:

Code: ags
int someInteger = 0;


I can't use someInteger anywhere above the declaration line...


Khris

Wow, this is the biggest steaming pile of utter miscommunication since a long time ago.

Quote from: AnasAbdin on Thu 18/08/2011 22:33:56
Khris I'm so sorry if I mislead you in a way...

You didn't mislead me in any way.

QuoteI wasn't referring to this specific problem (leave_room) when I mentioned java... I was talking about positioning this line in the code:
Code: ags
int someInteger = 0;


...bla java bla...

I AM AWARE OF THAT.
And that was exactly my point. What the hell has java got to do with this thread AT ALL, FFS?
And you mentioned Java a good deal before starting to ramble about variables, btw.

So:

1) I am familiar with Java, have already coded in Java and of course know about the differences between Java and AGS script.

2) Why do you keep posting about variables and Java when neither topic is in ANY WAY relevant to the thread AT ALL?
I'm going to repeat myself: why did you even mention Java in the first place? Yeah, you can use variables before declaring them. So what? What does this have to do with the problem that caused this thread? ZERO. NOTHING AT ALL.
What comparison? Where is the relation? THERE IS NONE.

3) How about instead of going on and on and on about a completely irrelevant issue (Java, variables) you address what I asked you about the ACTUAL PROBLEM, huh?
You didn't even mention in passing which values you got for player.y. Why not resolve this issue so that others can learn from it?
Using a region is a viable workaround, but the code you used initially should have worked, so let's find out what's wrong, agreed?

Seriously, if I'm going to have to read Java again in this thread I'll probably start screaming.

monkey0506

Java. :D

Hey, somebody had to do it. And it's good to see that my post was completely ignored. Glad to know that I've helped in resolving your issues. I mean..wait..uh..is this even resolved? What's going on here? Where am I? Who am I? What am I doing here? ARRRGGHHH!!

ddq

lol java. it makes poopy programmers.

KodiakBehr

Not to hijack the thread or anything...I'm sure this obstacle can be easily resolved...but in regards to,

Quote from: monkey_05_06 on Fri 19/08/2011 02:59:51
And it's good to see that my post was completely ignored. Glad to know that I've helped in resolving your issues. I mean..wait..uh..is this even resolved? What's going on here? Where am I? Who am I? What am I doing here? ARRRGGHHH!!

I actually go out of my way to read yours, and Khris' responses simply because you both speak fountains of truth.  So while it may or may not have been ignored by your intended target, I assure you that I'm following along and nodding in agreement in the back of the class.

SMF spam blocked by CleanTalk