[SOLVED] Why do these have different results?

Bentley

Member
I wrote some simple code to move instances of "parWrap", and a camera, to the other side of the room. The code is below. Why does the first work and not the second? The second makes the screen flash white for a frame. They are both called in the step event of oPlayer. The only child of parWrap is oPlayer.

oPlayer
Step Event (Good)
GML:
// Wrap
if (x > RIGHT_SIDE)
{
    x -= WRAP_DIST;
    with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) - WRAP_DIST, camera_get_view_y(camera));
}
else if (x < LEFT_SIDE)
{
    x += WRAP_DIST;
    with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) + WRAP_DIST, camera_get_view_y(camera));
}
=========================================================================================================================================================

oPlayer
Step Event (Bad)
GML:
// Wrap
if (x > RIGHT_SIDE) wrapWorld(-WRAP_DIST);
else if (x < LEFT_SIDE) wrapWorld(WRAP_DIST);
/// @func wrapWorld(_wrapDist)
GML:
function wrapWorld(_wrapDist)
{
    with (parWrap) x += _wrapDist;
    with (oCamera) camera_set_view_pos(camera, camera_get_view_x(camera) + _wrapDist, camera_get_view_y(camera));
}
The only difference I see is that the first doesn't have the code in a function. It's a very small project so I don't know what else could be causing the problem. There's one instance of each object (oPlayer and oCamera). Thanks for reading.'
 
Last edited:

GoK

Member
The first one executes "x += WRAP_DIST;" in scope of the oPlayer. The second in parWrap. Can it be the reason?
 

Bentley

Member
The first one executes "x += WRAP_DIST;" in scope of the oPlayer. The second in parWrap. Can it be the reason?
Thanks for the reply. Yes, I forgot to add that the only child of parWrap is oPlayer. But as to that being the reason, I don't understand why it would be. I still think the code should have identical results.
 

Bentley

Member
Have you tried to use any GMS's debuging tools?
The problem, oddly, is that I'm calling the parent object. I don't understand why it's not working. It is annoying b/c I have to use an array to wrap each "wrappable" instance instead of just using with (parWrap)
 

woods

Member
how lax is GML on missing brackets?

if (this is true)
{
do this
}



Code:
if (x > RIGHT_SIDE) wrapWorld(-WRAP_DIST);
else if (x < LEFT_SIDE) wrapWorld(WRAP_DIST);
vs

Code:
if (x > RIGHT_SIDE) 
{
wrapWorld(-WRAP_DIST);
}
else if (x < LEFT_SIDE) 
{
wrapWorld(WRAP_DIST);
}
 

GoK

Member
Well, I just replicate both versions of your setup in a new project and both are working fine. I added only independent movement for the player and camera.
The problem must be in some other piece of code.
 
Top