As you can read in the title, there is it. I'm testing a script and I need some functions to be executed in round one, but the script only returns the value once you change the map, so the value resets and it actually executes the code, but if you open the game, create a game, and click "Fight!", it won't return value "1", only sometimes, if you open the editor and then close it. This also happens with Game.IsFirstUpdate.
Is this supposed to be like that? or I'm just missing something?
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.
New to the forum? Say hello in this topic! Also make sure to read the rules.
Game.MapRound does not return value "1"
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
- JakSparro98
- Superfighter
- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 25
I don't think this has to do with a core game bug, more a problem with the script I suppose, you should provide an example map or at least the script itself.
0 x
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
I have an "if" checking the map round on a method executed on OnStartup and it just simply don't execute the code inside...
I also have tried executing it on AfterStartup
I also have tried executing it on AfterStartup
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
- 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
I'm not sure what you need.
MapRound is incremented each time the same map restarts (after a win or loss). It's reset when the map actually changes ("/changemap") to another map.
IsFirstUpdate is a boolean to indicate if the update run is the first update for the map or not (not for a specific script). If you start a script in the middle of a map it will return false as the map's first update is already run.
You can use the public void AfterStartup() and public void OnShutdown() functions to run arbitary code in your script once the script start and stops (no matter how it's started or stopped). This is where you should place code to restore/save your script's state if you need into Game.Data between rounds.
Note that all scripts stop and restarts when a map restarts/changes if I recall correctly.
If you could tell what you're trying to achieve we might be able to help better.
MapRound is incremented each time the same map restarts (after a win or loss). It's reset when the map actually changes ("/changemap") to another map.
IsFirstUpdate is a boolean to indicate if the update run is the first update for the map or not (not for a specific script). If you start a script in the middle of a map it will return false as the map's first update is already run.
You can use the public void AfterStartup() and public void OnShutdown() functions to run arbitary code in your script once the script start and stops (no matter how it's started or stopped). This is where you should place code to restore/save your script's state if you need into Game.Data between rounds.
Note that all scripts stop and restarts when a map restarts/changes if I recall correctly.
If you could tell what you're trying to achieve we might be able to help better.
0 x
Gurt
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
Yesterday I was out of my house so I couldn't open my script on Visual Studio.
I think this piece of the script should be enough (in fact, it's the only parts in which I use what I mentioned above)
I think this piece of the script should be enough (in fact, it's the only parts in which I use what I mentioned above)
Code: Select all
public void AfterStartup()
{
GameController.Init();
Events.PlayerDeathCallback.Start(OnPlayerDeath);
Events.PlayerDamageCallback.Start(OnPlayerDamaged);
}
// script...
public static class GameController
{
public static void Init()
{
if (Game.MapRound == 1)
{
// Some code that isn't working on the very first round, only after first map change.
}
Events.UpdateCallback.Start(UpdateManager, 500);
Events.UserMessageCallback.Start(OnCommand);
}
// script...
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
-
- Superfighter
- Posts: 97
- Joined: Thu Feb 07, 2019 4:36 am
Your code works fine, you can log to console and use SFD Map Debug window (Hit F7 in Map Editor) to confirm it.
Code: Select all
public void AfterStartup()
{
GameController.Init();
}
public static class GameController
{
public static void Init()
{
if (Game.MapRound == 1)
{
Game.WriteToConsole("Map round 1");
}
}
}
0 x