Forum C# Force code to be executed line by line

Force code to be executed line by line

Postby paala2 » March 8th, 2013, 1:56 pm

Hello,
I have a major problem here. This is my code (pseudo):
Code: Select all
for (int i = 0; i <= 44; i++){
                            //code not included irelevant
                                if (i == 43)
                                    PayVault vault = player.PayVault;

                                    //delegate
                                      vault.Refresh(delegate(){
                                     if (vault.Has("Gun44")){}
                                     else { hascheated = true;  Console.WriteLine("hascheted"); }
                                         
                                      });
                                }
                            }
                            Console.WriteLine("hascheated?:" + hascheated);
                           
                            if (hascheated == false)
                            {
                                //player.gold = goldtemp;//pui goldul player.glod de la inceput cu ceea ce se scade
                                player.PlayerObject.Set("gold", player.gold);
                                player.PlayerObject.Save();
                             
                            }





It seams that the code is executed line by line until i =43 , then instead of executing the payvault check for item and put the hascheated= true; this code is postponed, has cheted remains false, the code with big db saving is executed and then after the code with payvault verification is executed.

How can i force the payvault check to be executed line by line. Help me please.
paala2
 
Posts: 36
Joined: November 4th, 2012, 10:13 am

Re: Force code to be executed line by line

Postby Henrik » March 8th, 2013, 3:05 pm

All the code in the vault Refresh delegate is executed asynchronously, on another thread, after the vault has been refreshed.

A simple solution to your problem is to ensure the vault has been refreshed for the user before you do your loop and check, and since you're running server-side, the absolutely simplest solution is to set PreloadPlayerObjects to true on your Game, that way the vault is pre-loaded when the player joins the room. That way, you only need to call Refresh if you modify that player's vault from outside your room, for example from the client, or from another room.

http://playerio.com/documentation/refer ... yerObjects
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Force code to be executed line by line

Postby paala2 » March 8th, 2013, 3:22 pm

the problem is that this is my case.
From client the player buys a premium item, and then sends a message to the server to save it's properties.
Then the server needs to check. hey the client really has this item. Can i save in big db ?
IS there a way to execute that code not asynchronously or i should find other ways to check is player has the payvault item. maybe at room starting point.
paala2
 
Posts: 36
Joined: November 4th, 2012, 10:13 am

Re: Force code to be executed line by line

Postby Henrik » March 8th, 2013, 3:49 pm

Well, put the code that deals with checking the item in the Refresh delegate, then? You have a fresh vault there, so you can check if the user really has the item, and modify BigDB if he has, and do something else if he doesn't.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Force code to be executed line by line

Postby paala2 » March 8th, 2013, 4:08 pm

hmm.. that's a neat solution, and i think it will work
thanks
paala2
 
Posts: 36
Joined: November 4th, 2012, 10:13 am


Return to C#



cron