Some instances working, others not.

J

JadedFox

Guest
Hello there, second post. I plan to be quite active on this forum as I'm also teaching my niece GML. I'm having trouble with my instances, I'm making a platform game with ladders similar to donkey kong, but only some of the instances are working. In order to do the collision detection I have a global variable called platcollide set to false, which turns true when you collide with the instance of a bounding box already on-screen and turns off your vertical movement. I've placed the boxes below the ladders and there are three ladders. Here is the code for the bounding boxes and the character:

In collide with character event:
platcollide = true;

In character step event:
if (S && platcollide = false)
{
y+=spd;
}

and character collide event with ladder:

platcollide = false;

Two of my ladders and bounding boxes work, and one of them doesn't. I have no idea why one of them does not work. Any clues guys and gals?

Thanks!

Regards.
 

Fielmann

Member
1) You say that platcollide is a global variable, but in your code it is an instance variable. Global variables are preceded with global..

2) The bounding boxes and the character both seem to have this variable platcollide. Just one of them having it should be enough.

3) Bounding box is a poor name for an object, because a bounding box already is a thing in Gamemaker. (It's an area that instances have that is defined by their sprite's collision mask.)

4) What is S?

5) S && platcollide = false probably gets interpreted as S && !platcollide (as opposed to !S && !platcollide or !(S && platcollide)). Is this want you want? In any case, it's better to use parentheses, because it might depend on a platform and may confuse the reader.
 
J

JadedFox

Guest
1) You say that platcollide is a global variable, but in your code it is an instance variable. Global variables are preceded with global..

2) The bounding boxes and the character both seem to have this variable platcollide. Just one of them having it should be enough.

3) Bounding box is a poor name for an object, because a bounding box already is a thing in Gamemaker. (It's an area that instances have that is defined by their sprite's collision mask.)

4) What is S?

5) S && platcollide = false probably gets interpreted as S && !platcollide (as opposed to !S && !platcollide or !(S && platcollide)). Is this want you want? In any case, it's better to use parentheses, because it might depend on a platform and may confuse the reader.
Excellent, thank you!
 
J

JadedFox

Guest
After some time and work, the box still is not working.

Char Code:
GML:
if (S && !global.platcollide && !global.box1)
{
y+=spd;
}
Box1 Collision:
Code:
global.platcollide = true;
global.bound = true;


Platform below the Bounding box (Box1):

if(global.platcollide && (!global.bound))
{
    global.patcollide = false;
} else
{
global.patcollide = true;
global.bound = false;
}
Box1 Collision with Char:
Code:
global.platcollide = true;
global.bound = false;
Box1 Create code:
Code:
global.bound = false;
Two of the boxes work, but the other one I just go straight through and go straight through the platform as though platcollide is true and bound is true.

Thanks

Regards.
 
J

JadedFox

Guest
Hello there, second post. I plan to be quite active on this forum as I'm also teaching my niece GML. I'm having trouble with my instances, I'm making a platform game with ladders similar to donkey kong, but only some of the instances are working. In order to do the collision detection I have a global variable called platcollide set to false, which turns true when you collide with the instance of a bounding box already on-screen and turns off your vertical movement. I've placed the boxes below the ladders and there are three ladders. Here is the code for the bounding boxes and the character:

In collide with character event:
platcollide = true;

In character step event:
if (S && platcollide = false)
{
y+=spd;
}

and character collide event with ladder:

platcollide = false;

Two of my ladders and bounding boxes work, and one of them doesn't. I have no idea why one of them does not work. Any clues guys and gals?

Thanks!

Regards.
Hello guys and gals, still having trouble and really stumped here D:
 

Nidoking

Member
What is S? You never answered that.

And what is the relationship between patcollide and platcollide?

And why do you have global variables to store whether something is colliding? That just seems like a horrible idea.
 
J

JadedFox

Guest
What is S? You never answered that.

And what is the relationship between patcollide and platcollide?

And why do you have global variables to store whether something is colliding? That just seems like a horrible idea.
S is the "S" key for checking when pressed, and patcollide was a typo i've now fixed. I'm trying to do the box thing to make something else work.

Regards.
 
J

JadedFox

Guest
Fixed it, I had double code somewhere. Here is the solution:

Char step code:
GML:
if (S && global.platcollide)
{
y+=spd;
}
 
Top