returns true all the time

Started by Kewun, Dec 10, 2016, 08:03 PM

Previous topic - Next topic

Kewun

function GetVehiclePrice(player)
{
  if ( player.Vehicle ) {
    return ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
  }
}

This code always returns "true" when it should display the price of vehicle
how do i fix that?

Luis_Labarca

#1
tried this with my role and I know well but not is you because you may have different the code if you like raisins all lcodigopara see as it is and fix it
function GetVehiclePrice(player)
{
local VehicleID2=ReadIniNumber( "vdb.ini", ""+player.Vehicle.ID+"", "Price");
if(VehicleID2 !=null)
{
return VehicleID2;
}
return 0;
}
My server RP
IP: 51.222.28.159:8194

Kewun

not work( still returns true

Luis_Labarca

My server RP
IP: 51.222.28.159:8194

KAKAN

Check for another function with the same name. You've done that mistake many times though :p
oh no

Mötley

#5
Dont you hate it when that happens?
Well at-least try this code, This worked for me, So I modified the code to work for your script. I hope it works....
function GetVehiclePrice(player)
{
local Price;
        Price = ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
if ( Price != null )
return Price;

return 0;
}

And If not IDK I would just play with the bool
function GetVehiclePrice(player)
{
local Price;
        Price = ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}

return 0;
}

you could attempt to read it as a string first the change the value to be an integer.

local convert = ReadIniString("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");

convert.tointeger() etc etc

just saying, Try goofing around with it

sorry just woke up and heading to work

Xmair

Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

.

Quote from: Xmair on Dec 11, 2016, 01:28 PM
Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.

You sure tho?

local Price;
        Price = ReadIniInteger(...);
.

Mötley

Quote from: . on Dec 11, 2016, 01:37 PM
Quote from: Xmair on Dec 11, 2016, 01:28 PM
Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.

You sure tho?

local Price;
        Price = ReadIniInteger(...);

Now both of you have me questioning this, This worked for me in the past as the file read something so it returned true instead, Then checking if that value is not null "Doesn't exist, an error whatever", It returns zero instead blah blah..

I will await for Kewuns Answer I suppose

Kewun, Could you add

print("The returned value: " + Price)

Kewun

yes  it worked thanks @Motley

KAKAN

Quote from: JiN_KaZaMa on Dec 11, 2016, 02:08 PMyes  it worked thanks @Motley

ROFL, this is the first time I'm seeing something like this lol
oh no

Mötley

There are many reasons as to why this is correct. Do I need to elaborate just a little?

KAKAN

Quote from: Mötley on Dec 11, 2016, 09:25 PMThere are many reasons as to why this is correct. Do I need to elaborate just a little?
No, you don't. Actually, when you use ReadIniInteger, you must expect a integer. If the file doesn't exist, it should throw an error instead of returning true or false. This will make all the newbies confused...( though no one uses the original INI plugin these days... )
oh no

Kewun