Forum C# Complete newbie question! [player.send()] issues.

Complete newbie question! [player.send()] issues.

Postby zapleaf » August 28th, 2013, 8:01 am

I have no idea how to word this question into google so I hope someone here can help me out.
my problem
Code: Select all
player.Send(Message message);
will not work for me the way I want it to.
This is the basic idea of the code:
Code: Select all
// inside a switch statment ...
pPlayer.Send("A");
loadDefaultStats(PlayerStats, pPlayer);
pPlayer.Send("B");
SetPlayerClass(PlayerStats, pPlayer);
pPlayer.Send("C");
pPlayer.Send("ProfileLoaded");

My goal here is to send a message to the client after the profile has been loaded or created. Message A and B will send, along with a send statement inside loadDefaultStats(); Hoever, after I call the SetPlayerClass(); which sets the variables for player base class, the player.send() no longer works. Here is the SetPlayerClass();
Code: Select all
public void SetPlayerClass(DatabaseObject playerStats, Player player)
        {
            // ... Here is a lot of code that sets the player base class variables.
            player.Send("D"); // <----  This will not send either!
           
        }

I am completely lost on ideas. I have tried so many things, from changing the way SetPlayerClass() takes in its arguments to recording the entire function. If someone could explain to me what is going on that would be awesome. Thanks! I love learning so do not be hesitant to linking me to some good articles or guides on why I am having this problem. The main reason I did not just half-ass a quick fix is because I wanted to trial and error until I figured out why C# acts this way, but I have hit my wall...
zapleaf
 
Posts: 16
Joined: August 13th, 2013, 12:31 pm

Re: Complete newbie question! [player.send()] issues.

Postby Henrik » August 28th, 2013, 9:15 pm

In what ways does SetPlayerClass modify the pPlayer variable?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Complete newbie question! [player.send()] issues.

Postby zapleaf » August 28th, 2013, 9:40 pm

At first i just used the basic call I see used in other functions then I set the player class to the player object from player.IO
Code: Select all
player.coins = playerStats.getDouble("Coins")
But then I tried another approch to see if I was just declairing varibles badly so I made a public void setDouble(double d1, double d2) inside player class to set the variables from inside the player class. Here is a big ugly block of code you are talking about incase I over looked something important you wish to look at. Currently the code looks like this:

Code: Select all
        public void SetPlayerClass(DatabaseObject playerStats, Player player)
        {
            //  ===== Now save this monster to player class=====
            player.Name = player.ConnectUserId.Remove(0, 6);    // Remove simple from simpleUSERNAME
            player.setInt(player.Rank, playerStats.GetInt("Rank"));
            player.setInt(player.Rank_Exp, playerStats.GetInt("Rank_Exp"));
            player.setInt(player.locX, playerStats.GetInt("LocX"));
            player.setInt(player.locY, playerStats.GetInt("LocY"));

            // Basic stats
            player.setDouble(player.Health, playerStats.GetDouble("Health"));
            player.setDouble(player.Stamina, playerStats.GetDouble("Stamina"));
            player.setDouble(player.Spirit, playerStats.GetDouble("Spirit"));

            // Spcial things.
            player.setInt(player.Home, playerStats.GetInt("Home"));
            player.setDouble(player.Coins, playerStats.GetDouble("Coins"));
            player.Sleeping = playerStats.GetBool("Sleeping");               //TODO:

            player.setDouble(player.Strength, playerStats.GetDouble("Strength"));
            player.setDouble(player.Endurence, playerStats.GetDouble("Endurence"));
            player.setDouble(player.Dexterity, playerStats.GetDouble("Dexterity"));
            player.setDouble(player.Reflexes, playerStats.GetDouble("Reflexes"));

            player.setDouble(player.Wisdom, playerStats.GetDouble("Wisdom"));
            player.setDouble(player.Knowledge, playerStats.GetDouble("Knowledge"));
            player.setDouble(player.Focus, playerStats.GetDouble("Focus"));
            player.setDouble(player.Intellect, playerStats.GetDouble("Intellect"));

            player.setDouble(player.Technique, playerStats.GetDouble("Technique"));
            player.setDouble(player.Hindsight, playerStats.GetDouble("Hindsight"));
            player.setDouble(player.Insight, playerStats.GetDouble("Insight"));
            player.setDouble(player.Forsight, playerStats.GetDouble("Forsight"));

            player.setDouble(player.Perception, playerStats.GetDouble("Perception"));
            player.setDouble(player.Willpower, playerStats.GetDouble("Willpower"));
            player.setDouble(player.Presence, playerStats.GetDouble("Presence"));
            player.setDouble(player.Awareness, playerStats.GetDouble("Awareness"));
            player.Send("SendSomething");                                  <---- This lil bugger is what is not working.
           
        }


Thinking about it all, maybe this function just does not work at all? I am still new to c# so some criticism would be appreciated. I for the most part copy past and modify code I 'think' works from my understanding of c++, and as3.
zapleaf
 
Posts: 16
Joined: August 13th, 2013, 12:31 pm

Re: Complete newbie question! [player.send()] issues.

Postby Henrik » August 29th, 2013, 1:20 am

I can't spot any errors right now, but the whole thing is a bit weird to me..

Why are you copying a lot of information from a DatabaseObject onto your own Player object, when you could just keep a reference to that DatabaseObject around? Or, just use the built-in PlayerObject and it's already there for you?

As for debugging, set some breakpoints in your code and see what happens. Step through it and see if it blows up at some point? (Or add debug logging statements if you're not comfortable with the debugger, either way is fine, you need to figure out if the code even reaches the point where it calls those Send methods.)
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Complete newbie question! [player.send()] issues.

Postby zapleaf » August 29th, 2013, 5:19 am

Alright thank you very much for giving me some advice. I will try keeping a reference for DB object and see what that does. I just thought there was no way to use DB Object outside of a call function such as Load, Create and ect... hehe I'm just very newbie with c# here :p
zapleaf
 
Posts: 16
Joined: August 13th, 2013, 12:31 pm


Return to C#