PDA

View Full Version : SetTimerEx problem


FTLOG
28/12/2011, 06:39 PM
Hello.

I have a little problem, and i'm desperate with this already - Everthing i tried failed, so i'm asking here for help. Here's the deal.

I do this in one of my custom functions - SetTimerEx( "MovingCamera", MOVING_CAMERA_FPS, true, "i", playerid );

It's a 50 millisecond timer which moves camera around player during the tutorial, so it's critical that i kill it at some point. But the timer won't even start. However, if i do -

SetTimerEx( "MovingCamera", MOVING_CAMERA_FPS, true, "i", playerid ), SetTimerEx( "MovingCamera", MOVING_CAMERA_FPS, true, "i", playerid );

It works for some reason. Until the point where i got to kill it, then it won't stop. I tried debuging it with printf's and messages and the timer won't start if i do SetTimerEx just once. No errors, warnings, nothing.

I tried it with y_timers too, and it just won't start.

I think this is SetTimerEx bug, because even if do MovingCamera( playerid ) { print( "It works!" ); return true; } nothing happens.

Has anyone got any experience on this?

coole210
28/12/2011, 07:41 PM
It could be the timer itself, post it's code.

FTLOG
28/12/2011, 07:46 PM
I don't think so, because, as i said, it won't execute even the print function, nothing. Here is the code anyway.

function MovingCamera( playerid ) {

RotateCameraAroundPoint( playerid, ServerInfo[ MainSpawnX ], ServerInfo[ MainSpawnY ], ServerInfo[ MainSpawnZ ], 2, 10, 3 );
return true;
}

And then this function

RotateCameraAroundPoint( playerid, Float:X, Float:Y, Float:Z, Offset_X, Offset_Y, Offset_Z ) {

SetPlayerCameraPos( playerid, X - Offset_X * floatsin( - PlayerInfoEx[ playerid ][ CameraSpawnAngle ], degrees ), Y - Offset_Y * floatcos( - PlayerInfoEx[ playerid ][ CameraSpawnAngle ], degrees ), Z + Offset_Z );
SetPlayerCameraLookAt( playerid, X, Y, Z + 0.5 );

PlayerInfoEx[ playerid ][ CameraSpawnAngle ] += 0.5;

if( PlayerInfoEx[ playerid ][ CameraSpawnAngle ] >= 360.0) PlayerInfoEx[ playerid ][ CameraSpawnAngle ] = 0.0;

return true;
}

coole210
29/12/2011, 12:10 AM
Well there's your problem, it's not "function" its "public"


forward MovingCamera(playerid);
public MovingCamera( playerid ) {

RotateCameraAroundPoint( playerid, ServerInfo[ MainSpawnX ], ServerInfo[ MainSpawnY ], ServerInfo[ MainSpawnZ ], 2, 10, 3 );
return true;
}

FTLOG
29/12/2011, 12:42 PM
'function' is just a macro, so i don't have to forward every public - #define function%0(%1) forward %0(%1); public %0(%1)

I am absolutely sure that this is related to SetTimerEx not passing a correct value, playerid. Even though this has never happened to me before.

MadeMan
29/12/2011, 12:45 PM
Show where you set and kill the timers.

FTLOG
29/12/2011, 01:39 PM
ShowXomnia( playerid ) {

PlayerInfo[ playerid ][ xTutStep ] = 0;
UpdatePlayer( playerid );

TextDrawSetString( IntroTxt[ playerid ][ 5 ], TutorialTitles[ PlayerInfo[ playerid ][ xTutStep ] ] );
TextDrawSetString( IntroTxt[ playerid ][ 6 ], TutorialStrings[ PlayerInfo[ playerid ][ xTutStep ] ] );

for( new i = 0; i < 7; i++ ) {

TextDrawShowForPlayer( playerid, IntroTxt[ playerid ][ i ] );
}

SetPlayerPos( playerid, ServerInfo[ MainSpawnX ], ServerInfo[ MainSpawnY ], ServerInfo[ MainSpawnZ ] );
SetPlayerFacingAngle( playerid, ServerInfo[ MainSpawnA ] );
SetPlayerInterior( playerid, ServerInfo[ MainSpawnInterior ] );
SetPlayerVirtualWorld( playerid, ServerInfo[ MainSpawnVirtualWorld ] );

SetPlayerCameraPos( playerid, ServerInfo[ MainSpawnX ] - TUTORIAL_CAMERA_OFFSET_X, ServerInfo[ MainSpawnY ] - TUTORIAL_CAMERA_OFFSET_Y, ServerInfo[ MainSpawnZ ] + TUTORIAL_CAMERA_OFFSET_Z );
SetPlayerCameraLookAt( playerid, ServerInfo[ MainSpawnX ], ServerInfo[ MainSpawnY ], ServerInfo[ MainSpawnZ ] );

TogglePlayerControllable( playerid, 0 );

Timer_xMoving[ playerid ] = SetTimerEx( "MovingCamera", MOVING_CAMERA_FPS, true, "i", playerid );
return true;
}

function FirstTutorial( playerid ) {

if( PlayerInfo[ playerid ][ xTutStep ] < 6 ) {

TogglePlayerControllable( playerid, 0 );

PlayerInfo[ playerid ][ xTutStep ]++;
OnPlayerUpdateEx( playerid );

TextDrawSetString( IntroTxt[ playerid ][ 5 ], TutorialTitles[ PlayerInfo[ playerid ][ xTutStep ] ] );
TextDrawSetString( IntroTxt[ playerid ][ 6 ], TutorialStrings[ PlayerInfo[ playerid ][ xTutStep ] ] );

return true;

}
else {

for( new i = 0; i < 7; i++ ) TextDrawHideForPlayer( playerid, IntroTxt[ playerid ][ i ] );

PlayerInfo[ playerid ][ xTutStep ] = 255;
UpdatePlayer( playerid );

KillTimer( Timer_xMoving[ playerid ] );

SetSpawnForPlayer( playerid );
SetCameraBehindPlayer( playerid );

}

return true;

}