Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Script working in map editor, but not when loaded externaly

Here you can find all solved gameplay problems and bugs (beginning from Pre-Alpha 1.8.8).
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
Locked
android7
Meatbag
Posts: 8
Joined: Sat Aug 27, 2016 11:54 am

Script working in map editor, but not when loaded externaly

Post by android7 » Sat Jun 30, 2018 3:37 pm

I was making a script in map editor, so I could easily test it. When it was done and fully working in editor, I copied it into text file in Scripts folder. But when I ran that, it promted me with "Boom method couldn't be found" message. The rest worked as intended.

Code: Select all

Random N = new Random();
public void OnStartup(){
	IObjectTimerTrigger timer = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger");
   	timer.SetIntervalTime(1000);
   	timer.SetRepeatCount(0);
   	timer.SetScriptMethod("SpawnBomb");
		timer.Trigger();

}

public void Boom(TriggerArgs args){
if(N.Next(0,10) >= 9){
	IObject ToKill =(IObject)args.Sender;
	ToKill.Destroy();	
}

}

public void SpawnBomb(TriggerArgs args){
	Vector2 Pos = new Vector2(N.Next(-550,550) , 300);	

	IObject Can = Game.CreateObject("Metal03A");
	Can.SetWorldPosition(Pos);
	Can.SetBodyType(BodyType.Dynamic);

	IObjectDestroyTrigger Delete = (IObjectDestroyTrigger)Game.CreateObject("DestroyTrigger");

	IObjectExplosionTrigger Exp = (IObjectExplosionTrigger)Game.CreateObject("ExplosionTrigger");
	Exp.SetBodyType(BodyType.Dynamic);
	Exp.SetWorldPosition(Pos);

	IObjectSpawnFireCircleTrigger Fire = (IObjectSpawnFireCircleTrigger)Game.CreateObject("SpawnFireCircleTrigger");
	Fire.SetBodyType(BodyType.Dynamic);
	Fire.SetWorldPosition(Pos);
	
	IObjectAreaTrigger Detect = (IObjectAreaTrigger )Game.CreateObject("AreaTrigger");
	Detect.SetBodyType(BodyType.Dynamic);
	Detect.SetSizeFactor(new Point(1,1));
	Detect.SetWorldPosition(Pos+new Vector2(0,-10));
	Detect.AddActivateTriggerOnEnter(Exp);	
	Detect.AddActivateTriggerOnEnter(Fire);	
	Detect.AddActivateTriggerOnEnter(Delete);
	Detect.SetOnEnterMethod("Boom");		//Boom method is being triggered by area trigger

	IObjectWeldJoint Weld = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
	Weld.SetWorldPosition(Pos);
	Weld.AddTargetObject(Detect);
	Weld.AddTargetObject(Exp);
	Weld.AddTargetObject(Fire);
	Weld.AddTargetObject(Can);
	
	
	Delete.AddObjectToDestroy(Detect);
	Delete.AddObjectToDestroy(Can);


}
I shloud add that I can run other scripts in my Scripts folder without problem
Last edited by KliPeH on Sat Jun 30, 2018 4:20 pm, edited 1 time in total.
Reason: Merged a double-post.
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1067
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 28

Post by Gurt » Sat Jun 30, 2018 5:57 pm

Already fixed in https://mythologicinteractiveforums.com ... 125#p16125
Use the Events.UpdateCallback instead of using a timer as a workaround:

Events.UpdateCallback.Start(SpawnBomb, 1000);
public void SpawnBomb(float elapsed) {
// Spawn bomby
}
2 x
Gurt

Locked

Who is online

Users browsing this forum: No registered users and 1 guest