Page 1 of 1
A way to skip parameters in method
Posted: Tue Jul 18, 2017 10:55 pm
by jamisco
take the method .. Player.AddCommand(new PlayerCommand(CommandType, TargetbjectID, delayTime))
say i want to input just commandtype and the delay time, how would i skip the TargetObjectID?
Re: A way to skip parameters in method
Posted: Wed Jul 19, 2017 9:29 pm
by JakSparro98
jamisco wrote: ↑Tue Jul 18, 2017 10:55 pm
take the method .. Player.AddCommand(new PlayerCommand(CommandType, TargetbjectID, delayTime))
say i want to input just commandtype and the delay time, how would i skip the TargetObjectID?
Player Command has many constructors, their parameters cannot be bypassed but you can fill some with useless data, if for instance i use the one with
PlayerCommand (PlayerCommandType action, Vector2 worldPosition, Int delayTime = 0) I will fill like that:
player.AddCommand(new PlayerCommand(PlayerCommandType.WaitLand,Vector2.Zero,20000));
Normally WaitLand doesn't use Vector2 type, so I guess this parameter will be ignored.
Re: A way to skip parameters in method
Posted: Thu Jul 20, 2017 4:09 am
by jamisco
i see, so how would you by pass target object id
Re: A way to skip parameters in method
Posted: Sun Jul 23, 2017 12:17 pm
by kirill240
jamisco wrote: ↑Thu Jul 20, 2017 4:09 am
i see, so how would you by pass target object id
If the TargetObjectID command does not affect the result of execution, then write any (better than 0) or use null
Re: A way to skip parameters in method
Posted: Thu Aug 03, 2017 4:10 pm
by Gurt
The PlayerCommand has several constructor overloads. Use the most appropriate one. Sending in the wrong parameters won't do anything if it can't be applicable.
Code: Select all
/*
// Example use:
IPlayer player = Game.CreatePlayer(Vector2.Zero);
player.AddCommand(new PlayerCommand(PlayerCommandType.StartMoveToPosition, new Vector2(100f, 0f))); // player will start to move to world position X = 100
player.AddCommand(new PlayerCommand(PlayerCommandType.Walk)); // player will walk instead of run
player.AddCommand(new PlayerCommand(PlayerCommandType.WaitDestinationReached)); // wait for destination reached
player.AddCommand(new PlayerCommand(PlayerCommandType.Jump, PlayerCommandFaceDirection.Left)); // jump after destination reached and face left
player.AddCommand(new PlayerCommand(PlayerCommandType.WaitLand)); // wait to land after jump
player.AddCommand(new PlayerCommand(PlayerCommandType.Dive, PlayerCommandFaceDirection.Left)); // dive to the left
// other actions
player.AddCommand(new PlayerCommand(PlayerCommandType.StartTakeCover, Game.GetSingleObjectByCustomID("BarrelWithCustomID").UniqueID)); // take cover behind object with custom ID "BarrelWithCustomID" (this also makes the player move to the cover if the player is too far away).
player.AddCommand(new PlayerCommand(PlayerCommandType.DrawHandgun)); // draws the handgun slot if the player has a handgun
player.AddCommand(new PlayerCommand(PlayerCommandType.StartCrouch)); // makes the player start crouching (until PlayerCommandType.StopCrouch is called)
*/