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.
Here you can find answered ScriptAPI topics.
-
Pixir
- Fighter
- Posts: 16
- Joined: Fri Aug 18, 2017 3:04 pm
- Gender:
- Age: 23
Post
by Pixir » Thu Feb 08, 2018 1:11 am
Code: Select all
public void Spawn(TriggerArgs args){
Vector2 worldPosition = Vector2.Zero;
Random rnd = new Random();
int y = rnd.Next(-200,200);
int x = rnd.Next(-200,200);
IObject Crate = (IObject)Game.CreateObject("HangingCrateHolder",new Vector2(y,x), 0f);
Crate.SetBodyType(BodyType.Static);
IObjectOnDestroyedTrigger Trigger = (IObjectOnDestroyedTrigger)Game.CreateObject("OnDestroyedTrigger");
Trigger.SetTriggerDestroyObjects(Crate);
Score();
}
I'm trying to make a script that spawns random HangingCrateHolder(s) and detects when they were destroyed but it doesn't seem to work
Code: Select all
CS1502 The best overloaded method match for 'SFDGameScriptInterface.IObjectOnDestroyedTrigger.SetTriggerDestroyObjects(System.Collections.Generic.IEnumerable<SFDGameScriptInterface.IObject>)' has some invalid arguments @(26, 2) Trigger.SetTriggerDestroyObjects(Crate);
CS1503 Argument 1: cannot convert from 'SFDGameScriptInterface.IObject' to 'System.Collections.Generic.IEnumerable<SFDGameScriptInterface.IObject>' @(26, 35) Trigger.SetTriggerDestroyObjects(Crate);
Any help is appreciated
Last edited by
Pixir on Thu Feb 08, 2018 5:58 pm, edited 2 times in total.
0 x
-
JakSparro98
- Superfighter
- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 25
Post
by JakSparro98 » Thu Feb 08, 2018 11:31 am
Pixir wrote: ↑Thu Feb 08, 2018 1:11 am
Code: Select all
public void Spawn(TriggerArgs args){
Vector2 worldPosition = Vector2.Zero;
Random rnd = new Random();
int y = rnd.Next(-200,200);
int x = rnd.Next(-200,200);
IObject Crate = (IObject)Game.CreateObject("HangingCrateHolder",new Vector2(y,x), 0f);
Crate.SetBodyType(BodyType.Static);
IObjectOnDestroyedTrigger Trigger = (IObjectOnDestroyedTrigger)Game.CreateObject("OnDestroyedTrigger");
Trigger.SetTriggerDestroyObjects(Crate);
Score();
}
I'm trying to make a script that spawns random HangingCrateHolder(s) and detects when they were destroyed but it doesn't seem to work
Code: Select all
CS1502 The best overloaded method match for 'SFDGameScriptInterface.IObjectOnDestroyedTrigger.SetTriggerDestroyObjects(System.Collections.Generic.IEnumerable<SFDGameScriptInterface.IObject>)' has some invalid arguments @(26, 2) Trigger.SetTriggerDestroyObjects(Crate);
CS1503 Argument 1: cannot convert from 'SFDGameScriptInterface.IObject' to 'System.Collections.Generic.IEnumerable<SFDGameScriptInterface.IObject>' @(26, 35) Trigger.SetTriggerDestroyObjects(Crate);
Any help is appreciated
Since the method accepts Generic Collections and arrays you only need to include the object inside one them:
Code: Select all
//Using arrays
IObject[] Objects=new IObject[1];
Objects[0]=Crate;
Trigger.SetTriggerDestroyObjects(Objects);
or
Code: Select all
//Using lists
List<IObject> Objects = new List<IObject>();
Objects.Add(Crate);
Trigger.SetTriggerDestroyObjects(Objects);
0 x
-
Pixir
- Fighter
- Posts: 16
- Joined: Fri Aug 18, 2017 3:04 pm
- Gender:
- Age: 23
Post
by Pixir » Thu Feb 08, 2018 12:44 pm
Thank you it worked
0 x
-
Pixir
- Fighter
- Posts: 16
- Joined: Fri Aug 18, 2017 3:04 pm
- Gender:
- Age: 23
Post
by Pixir » Thu Feb 08, 2018 5:57 pm
Code: Select all
public void Spawn(TriggerArgs args){
Vector2 worldPosition = Vector2.Zero;
Random rnd = new Random();
int y = rnd.Next(-200,200);
int x = rnd.Next(-200,200);
IObject Crate = (IObject)Game.CreateObject("HangingCrateHolder",new Vector2(y,x), 0f);
Crate.SetBodyType(BodyType.Static);
Crate.CustomID ="Aim";
IObjectOnDestroyedTrigger Trigger = (IObjectOnDestroyedTrigger)Game.CreateObject("OnDestroyedTrigger");
IObject[] Objects=new IObject[1];
Objects[0]=Crate;
Trigger.SetTriggerDestroyObjects(Objects);
Trigger.CustomID="Aim5";
Trigger.SetScriptMethod("ScoreUp");
Score();
IObjectTimerTrigger Timer = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger");
Timer.SetIntervalTime(3000);
Timer.SetRepeatCount(1);
Timer.SetScriptMethod(Delete(Crate,Trigger));
Timer.Trigger();
}
public void Delete(IObject Crate,IObjectOnDestroyedTrigger Trigger){
Trigger.Destroy();
Crate.Remove();
}
How to make the function to wait for 2000ms and then delete the trigger and the HangingCrateHolder?
Any help is appreciated
0 x
-
Gurt
- Lead Programmer
- Posts: 1884
- Joined: Sun Feb 28, 2016 3:22 pm
- Title: Lead programmer
- Started SFD: Made it!
- Location: Sweden
- Gender:
- Age: 34
Post
by Gurt » Thu Feb 08, 2018 7:42 pm
Do a "fire and forget" update event.
Code: Select all
Events.UpdateCallback.Start((float e) => { yourTrigger.Remove(); }, 2000, 1);
First parameter is an Action<float>, second the minimum game time to elapse in milliseconds (2000 for 2 seconds) and the third is the repeat count. Set it to 1 to only trigger the action once.
1 x
Gurt
-
Pixir
- Fighter
- Posts: 16
- Joined: Fri Aug 18, 2017 3:04 pm
- Gender:
- Age: 23
Post
by Pixir » Fri Feb 09, 2018 10:57 am
Thank you it worked
0 x