Forum C# Read a playerobject property from the serverside

Read a playerobject property from the serverside

Postby flexcool354 » September 29th, 2010, 5:51 pm

I am really bad at c#, but i am even worse at the other serverside languages.
I need to read a property from a playerobject on my serverside in a simple if statement but i am completely lost

i managed to get here, and now i am like how do i reach the desired property

Code: Select all
Callback<DatabaseObject> callback = null;
i.GetPlayerObject(callback);
if (callback.? == )
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Read a playerobject property from the serverside

Postby default0 » September 29th, 2010, 6:14 pm

flexcool354 wrote:I am really bad at c#, but i am even worse at the other serverside languages.
I need to read a property from a playerobject on my serverside in a simple if statement but i am completely lost

i managed to get here, and now i am like how do i reach the desired property

Code: Select all
Callback<DatabaseObject> callback = null;
i.GetPlayerObject(callback);
if (callback.? == )


basically you can go like this:

Code: Select all
i.GetPlayerObject(
delegate(DatabaseObject playerObject)
{
    if (playerObject.GetValue("<name of the property you want to read here>") == something)
    {
        // do something here
    }
});


I haven't worked with GetPlayerObject myself, but this code above used to work, just replace the string with the name of your property and the something variable with whatever you want to compare to :)

Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: Read a playerobject property from the serverside

Postby flexcool354 » September 29th, 2010, 6:29 pm

thanks i'll try it
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Read a playerobject property from the serverside

Postby flexcool354 » September 29th, 2010, 7:20 pm

okay it kinda works, but i need to see if the value is true, and that gives me this error
Error 2 Operator '==' cannot be applied to operands of type 'object' and 'bool'
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Read a playerobject property from the serverside

Postby default0 » September 30th, 2010, 10:06 am

flexcool354 wrote:okay it kinda works, but i need to see if the value is true, and that gives me this error
Error 2 Operator '==' cannot be applied to operands of type 'object' and 'bool'



Okay, then use this code here:

Code: Select all
i.GetPlayerObject(
delegate(DatabaseObject playerObject)
{
    if(playerObject.GetBool("<your property name here>"))
    {
        // do something here
    }
});



There are several other data types, too.
Int = Whole numbers, positive or negate (1, 2, 3, -2, -3 etc)
Uint = Whole numbers, only positive (1, 2, 3, 0, etc)
Float = Floating point numbers (1.3, 2.3, -1.4 etc)
Double = Floating point numbers (more precise, uses 8 bytes) (1.3, 2.3, -1.4 etc)
Boolean = Either true or false
Long = Whole Numbers, positive or negative, but also supports really large numbers
Ulong = Whole positive numbers, also supports really large numbers
String = set of characters ("test", "asdf" etc)

I guess these are the ones you have to use.
So, to BigDB, if you have an Int saved on your DB Object use
myObject.GetInt("someproperty");
For Uint
myObject.GetUInt("someproperty");
For String
myObject.GetString("someproperty");
For Long
myObject.GetLong("someproperty");
For Float
myObject.GetFloat("someproperty");
For Double
myObject.GetDouble("someproperty");
For Boolean
myObject.GetBool("someproperty");

Also I guess that reading the documentation may certainly be helpful for you :)

Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: Read a playerobject property from the serverside

Postby flexcool354 » September 30th, 2010, 1:12 pm

Thanks

I've actually figured that out myself, not the way you did, but by using some convert.toBoolean, and yes I've read a lot of documentation already, it is just that c# really confuses me at points
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm


Return to C#



cron