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.

Game.MapRound does not return value "1"

Did you encounter a problem, exploit, glitch or bug while playing the game or running the dedicated server software? Tell us about it here.
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
Post Reply
User avatar
Mr Argon
Fighter
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

Game.MapRound does not return value "1"

Post by Mr Argon » Fri Feb 21, 2020 4:01 am

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?
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.

User avatar
JakSparro98
Superfighter
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 » Fri Feb 21, 2020 9:54 pm

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

User avatar
Mr Argon
Fighter
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

Post by Mr Argon » Sat Feb 22, 2020 1:40 am

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
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.

User avatar
Gurt
Lead Programmer
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 » Sat Feb 22, 2020 2:47 pm

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.
0 x
Gurt

User avatar
Mr Argon
Fighter
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

Post by Mr Argon » Sat Feb 22, 2020 4:53 pm

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)

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тн тнат.

NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

Post by NearHuscarl » Mon Feb 24, 2020 3:35 pm

Your code works fine, you can log to console and use SFD Map Debug window (Hit F7 in Map Editor) to confirm it.

Image

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
Image

Post Reply