dini_Get returning nothing ("")
#1

Hi all,
Im having an unusual problem with dini - ive never had it before...

I am creating my own house system (possible release here if its good enough ) - and i am trying to do dini_Get(file, "owner") and compare it using strcmp to see if its owned or not... - But even when the house is owned (A name is in 'Owner')

Here is the corresponding code:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    new file[64], pName[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    for(new i; i < LastID; i++)
    {
        if(pickupid == Pickups[i])
        {
            format(file, sizeof(file), "houses/%i.house", i);
            if(strcmp(dini_Get(file, "Owner"), "") == 0)
            {
                SendClientMessage(playerid, COLOUR, "This house is for sale");
                if(dini_Int(file, "Type") == 0)
                {
                    format(string, sizeof(string), "It costs: %i and is a very small house", dini_Int(file, "Cost"));
                }
                else if(dini_Int(file, "Type") == 1)
                {
                    format(string, sizeof(string), "It costs: %i and is a small house", dini_Int(file, "Cost"));
                }
                else if(dini_Int(file, "Type") == 2)
                {
                    format(string, sizeof(string), "It costs: %i and is a medium house", dini_Int(file, "Cost"));
                }
                else if(dini_Int(file, "Type") == 3)
                {
                    format(string, sizeof(string), "It costs: %i and is a big house", dini_Int(file, "Cost"));
                }
                else if(dini_Int(file, "Type") == 4)
                {
                    format(string, sizeof(string), "It costs: %i and is a very big house", dini_Int(file, "Cost"));
                }
                else if(dini_Int(file, "Type") == 5)
                {
                    format(string, sizeof(string), "It costs: %i and is a massive house", dini_Int(file, "Cost"));
                }
            }
            else if(strcmp(dini_Get(file, "Owner"), pName) == 0)
            {
                format(string, sizeof(string), "You own this house, it cost %i", pName, dini_Int(file, "Cost"));
            }
            else
            {
                format(string, sizeof(string), "%s owns this house, it cost them %i", dini_Get(file, "Owner"), dini_Int(file, "Cost"));
            }
            SendClientMessage(playerid, COLOUR, string);
           
            printf("DINI: %s, pName: %s", dini_Get(file, "Owner"), pName); //As you can see here - i tried printing - i have shown what came out below
           
        }
    }
}
Here is the proof of it not doing anything...

Код:
[11:09:33] DINI: , pName: Ash
Thanks in advance for your help
Ash!
Reply
#2

Well, with strcmp, the return is not as simple as if they match it's 1, and if they don't it's 0. It's actually a little more complex, although I don't think the SA-MP Wiki explains the return value perfectly either.

What you must remember though specifically, is that using strcmp to compare an empty string to a string will actually always come up with 0.

Therefore:

pawn Код:
if(strcmp(dini_Get(file, "Owner"), "") == 0)
Will always be true.

Although I cannot explain why later on it does not print out a name.
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well, with strcmp, the return is not as simple as if they match it's 1, and if they don't it's 0. It's actually a little more complex, although I don't think the SA-MP Wiki explains the return value perfectly either.

What you must remember though specifically, is that using strcmp to compare an empty string to a string will actually always come up with 0.

Therefore:

pawn Код:
if(strcmp(dini_Get(file, "Owner"), "") == 0)
Will always be true.

Although I cannot explain why later on it does not print out a name.
Thanks, how else would i compare the two strings - using
pawn Код:
if(string == string2)
gives errors.
Reply
#4

Quote:
Originally Posted by funky1234
Посмотреть сообщение
Thanks, how else would i compare the two strings - using
pawn Код:
if(string == string2)
gives errors.
Well that's the only way to do it really (using strcmp).

So specifically for checking if a string is empty, just use strlen.

pawn Код:
if(strlen(string) == 0) // String is empty
Reply
#5

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Well that's the only way to do it really (using strcmp).

So specifically for checking if a string is empty, just use strlen.

pawn Код:
if(strlen(string) == 0) // String is empty
Thanks, but that still doesnt explain why dini_Get is still returning "{nothing}" - Even though, if i check the file, there is "Ash" in the key. (Ash is my SAMP Game name)
Reply
#6

Not sure what the issue is there. Bare in mind that on Linux systems the filesystem is case-sensitive, so you need to make the directory and file the same case as in the script. Most hosts use Linux.
Reply
#7

I host myself and have a dedicated linux server - i also test on a windows server (my laptop) but i keep to the same rule (case sensitive)

I can get integers and float data from the same file, just not strings. Its actually really annoying now - Is it worth trying to change the .house file association to .ini ?

Thanks
Ash
Reply
#8

Have you tried printing out i?

So you can make sure the ID of the house is indeed correct.
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Have you tried printing out i?

So you can make sure the ID of the house is indeed correct.
I havent tried that yet - ill give it a try now,

Just incase you're wondering:
in the UK it has snows and Nottinghamshire (where i live) is very very icy, so my school is closed today

EDIT: I am now testing all my scripts in 0.3c - i have tested the code above, in my first post, and now it seems OnPlayerPickupPickUp doesnt work at all... - Any ideas?

Quote:
EDIT: I am now testing all my scripts in 0.3c - i have tested the code above, in my first post, and now it seems OnPlayerPickupPickUp doesnt work at all... - Any ideas?

OnPlayerPickupPickUp does work, its just pickupid = 0;, all the time. - Any Ideas?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)