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.

[Guide] Removing the "error" block w. Script

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Mighty Spirit the 2
Superfighter
Superfighter
Posts: 187
Joined: Mon Jun 25, 2018 5:02 pm
Title: Wasted potential
SFD Account: ake004
SFD Alias: Retired SFD player
Started SFD: When melee was good
Location: SFD Veteran trauma hospital
Gender:
Age: 22

[Guide] Removing the "error" block w. Script

Post by Mighty Spirit the 2 » Fri Aug 26, 2022 11:34 pm

How to remove "error" block via script

This is a guide on how to detect and remove this thing: https://i.imgur.com/CMMLUJE.png

Basically this happens if you try to spawn something into the game that doesn't exist or it does not recognize. This virtually only happens if you utilize scripts. I am working on a script that is supposed to be cross-compatible with steam and previous versions of the game, but since Steam was updated with new items, creating certain objects will trigger the error block. I'm sure this can also be helpful for people who are developing scripts for Redux and people try to run it in steam. Below are two methods I figured out.


At first I wasn't sure it was an object at all, but in map editor if you hover over with mouse and press Alt_Gr, it will show the name ("error", ID: x).
https://i.imgur.com/AWCl6Un.png
First thing I tried was foreach(Iobject o in Game.GetObjectsByName("error")), and try to (o.)remove() it. This didn't work, for some reason it can't filter the name itself. Then I tried another method:

Method 1 - via CustomID (CheckForErrors)


If your script is set to create any Object from a list containing objects you know aren't existing in previous versions (For me it was WeaponItems), you can set the spawned item to have a CustomID, for example ("CreatedObject"). Then you can do foreach(Iobject o in Game.GetObjectsByCustomID("CreatedObject") ) { if o.name=="error" o.Remove(); } } This will work for some reason, you can also run if the name is not "error" set CustomID.StringEmpty.

Method 2 - via Area (CheckForErrors2)

With this method you will get all objects that are created within the camera area. This will make it so you don't have to assign a customID to objects. Else it's the same as above. I'm not sure how it will work for mulitple CameraAreaTriggers. It worked for at least one more.


For both these methods, i illustrated the effect with a Button trigger, you can basically copy what map i made in the pictures, set the Button to have Script method "Button".

Code: Select all

List<String> Object = new List<String>();
Random rnd = new Random();

public void OnStartup() {
Events.UpdateCallback.Start(CheckForErrors, 5000); //Reason i put this 5 seconds is so you have time to see it work by itself. Normally put this to 0.
Object.Add("Barrel00");
Object.Add("UnrealObject");
}

 public void Button(TriggerArgs args) {
IObject c = Game.CreateObject(Object[rnd.Next(0,Object.Count)]);
IObject d = Game.CreateObject(Object[rnd.Next(0,Object.Count)], new Vector2(124,68));
Game.RunCommand("/MSG " + c.Name.ToString()); //See name is "error"
c.CustomID="CreatedObject";
d.CustomID="CreatedObject";
}

public void CheckForErrors(float ms) { 
foreach(IObject a in Game.GetObjectsByCustomID("CreatedObject") ) if(a.Name=="error") { a.Remove(); } else { a.CustomID=String.Empty; }
Game.PlayEffect("CFTXT", new Vector2(0,0), "One cycle past");
}

public void CheckForErrors2(float ms) { 
foreach(IObject a in Game.GetObjectsByArea(Game.GetCameraMaxArea())) if(a.Name=="error") { a.Remove(); } else { a.CustomID=String.Empty; }
Game.PlayEffect("CFTXT", new Vector2(0,0), "One cycle past");
}
//Object d was for testing object w. another CameraAreaTrigger.

Hopefully this will help some people in the future. It would be nice if one of these methods were included in any script (related to creation of objects) that people make, to ensure removal of "Error" block of versions script wasn't intended for.

Do you have a better way? I didn't find any on this forum (that's why i decided to share this), but if you do comment below!
0 x
🎶I will tell your story if you die
I will tell your story and keep you alive the best i can
...
But I've always had the feeling we would die young
Some die young
🎵
https://i.imgur.com/D479VLi.png

Post Reply