Page 1 of 1

SpawnProjectile still expecting "type"

Posted: Tue Apr 12, 2016 11:40 pm
by TheOriginalCj
Written like so:
IObject ratatat = Game.SpawnProjectile(6,LeftNut.GetWorldPosition(), new.Vector2(108));

Column 74 is giving me the Type Expected error (CS1031)

So... Whaddup?

Re: SpawnProjectile still expecting "type"

Posted: Wed Apr 13, 2016 12:23 am
by ShutDownMan
Simple, this function returns you void and not IObject '-'

Re: SpawnProjectile still expecting "type"

Posted: Wed Apr 13, 2016 2:05 am
by TheOriginalCj
ShutDownMan wrote:Simple, this function returns you void and not IObject '-'
The Error is in char 74, not 1. It's still asking for the type.

EDIT: Clarifying the error, it seems to be Vector2 that's sending the error, perhaps it's not compatible in this command?

Re: SpawnProjectile still expecting "type"

Posted: Wed Apr 13, 2016 3:21 am
by ShutDownMan
Ýeah, I just saw an error before it appeared =P

There's a lot of wrong things there, so I think it's better I show you the right way to set up a SpawnProjectile:
In this example:

Code: Select all

public void ActivateShooter(TriggerArgs args){
	IObject obj01 = Game.GetFirstObject("Object01") as IObject;
	IObject obj02 = Game.GetFirstObject("Object02") as IObject;

	if(obj02 != null){ // if object01 still exists
		Vector2 pos01 = obj01.GetWorldPosition();
		Vector2 pos02 = obj02.GetWorldPosition();

		Vector2 direction = pos02 - pos01;

		Game.SpawnProjectile(ProjectileItem.M60, pos01, direction);
	}

}
You can see that the first argument is put in this way: ProjectileItem.M60
There's no problem if you put ProjectileItem.6, but I find the first way better when debugging code.

The second argument is just the position of the "shooter", and the third argument is the subtraction of the position of the second object from the first one.

Hope I helped, at least a bit.

Re: SpawnProjectile still expecting "type"

Posted: Wed Apr 13, 2016 6:11 am
by TheOriginalCj
You didn't only help a bit, you helped alot. Thanks for the help ShutDownMan.

EDIT: As a side note, the Numeric ID for ProjectileItem does not work. You have to use the ID of the weapon.

Re: SpawnProjectile still expecting "type"

Posted: Thu Apr 28, 2016 1:04 am
by chelog
TheOriginalCj wrote:EDIT: As a side note, the Numeric ID for ProjectileItem does not work. You have to use the ID of the weapon.
Shut was a lil' wrong (or he may mistype). Actually, you can use just 6 instead of ProjectileItem.M60. But the thing that if Gurt changes numerical index of projectiles in future, your script may spawn some other projectile instead of M60 one. So you'd better use Enumerations as ShutDownMan said.