Author Topic: Execute a forced addon crashes at loading  (Read 1070 times)

I have this weird problem where I use ForceRequiredAddOn and I crash while loading.
It doesn't happen with using the exact function, but when I execute the required addon after forcing it.

I force other addons and they don't crash while I copied their code.

Loading the addon normally also works perfectly.

Code: [Select]
%error = ForceRequiredAddOn("Bot_Spongebob");

if(!(%error == $Error::AddOn_NotFound))
{
   //we don't have the jeep, so we're screwed
   error("ERROR: Bot_Spongebob - required add-on not found");
}
else
{
   exec("Add-Ons/Bot_Spongebob/server.cs"); //This makes me crash.
}

Anyone encountered that problem before or maybe knows a way to fix this?

You have local variables. Use global variables.

You have local variables. Use global variables.
What? No? There's nothing wrong with what he has.

Code: [Select]
%error = ForceRequiredAddOn("Bot_Spongebob");

if(%error == $Error::AddOn_NotFound)
{
   //we don't have the jeep, so we're screwed
   error("ERROR: Bot_Spongebob - required add-on not found");
}
else
{
   exec("Add-Ons/Bot_Spongebob/server.cs"); //This makes me crash.
}
try this; the if statement looked off for what you wanted to do

and no there isn't a syntax error in this code (anymore)
« Last Edit: December 29, 2015, 03:28:16 PM by QuadStorm »

There's a syntax error in that. What he had was valid.

!(%error == $Error::AddOn_NotFound) is the same as %error != $Error::AddOn_NotFound

ForceRequiredAddon automatically executes it. Don't execute it again.

What? No? There's nothing wrong with what he has.

Local variables in the global scope love to crash dedicated servers (though that's probably not the issue here).

Yeah, I got the code from the sticky:
http://forum.blockland.us/index.php?topic=147039.0

And the exact same code works on other addons, just not on that playertype.

Is it maybe the sequence the addons are loaded in or something?


ForceRequiredAddon automatically executes it. Don't execute it again.
So, the code on the sticky obsolete now?

-edit-
I just tested without the execute line and it didn't load.


Local variables in the global scope love to crash dedicated servers (though that's probably not the issue here).
If that is the case, then I should certainly change them.
« Last Edit: December 29, 2015, 03:24:27 PM by honytawk »

Local variables in the global scope love to crash dedicated servers (though that's probably not the issue here).
i can imagine when he executes the Bot_Spongebob addon it crashes the game because maybe that uses local variables in the global scope

so go into Bot_Spongebob/server.cs and remove the local variables from there and it should work

edit: mixed up global/local, reread post if you saw it before

It didn't crash anymore, but the addon didn't load either.
So I found out I had to enable the bot_hole for the playertype to work.
Then I saw the bot_spongebob addon didn't forceload the bot_hole, but instead used its own version for some reason.
It used this code:
Code: [Select]
if(LoadRequiredAddOn("Bot_Hole") == $Error::None)
exec("./bot_base.cs");

After I changed this to my code, it does work.
Yet it still gives the error: "Bot_Spongebob - required add-on not found".

Well, it is something weird. But as long as everything is loaded correctly, I don't mind.

What? No? There's nothing wrong with what he has.
Yes there is, if you reexec the mod (why would you, but he did that), it will crash the server.

Don't ever use local variables outside of a function when exec a file, you'll most likely crash.

I've never once crashed using local variables outside of a function. I mean, I don't use it often because there's typically no reason to, but still. I'll take your word on it though.

I've never once crashed using local variables outside of a function. I mean, I don't use it often because there's typically no reason to, but still. I'll take your word on it though.
Use a local variable for a for statement outside of a function and when you start a server it'll just load endlessly.

Use a local variable for a for statement outside of a function and when you start a server it'll just load endlessly.
That's because you've used the same variable name as the loop to execute add-ons.

eval() and exec() don't create a new variable context like calling a ts function does. The script you're loading can access local vars from the function that loaded it, and the other way around.

For example, put this in a file called config/test.cs: echo(%blah);
Then run this in your console: %blah = "hi"; exec("config/test.cs");