SA-MP Forums Archive
[Solved] How to return to float? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Solved] How to return to float? (/showthread.php?tid=88936)



[Solved] How to return to float? - arnutisz - 29.07.2009

How to return to float value? I tried, but I failed
pawn Код:
new Float:value;
value = floatstr(fromline[1]);
return value;
I get warning about tag mismatch in line "return value". 'return Float:value' doesn't work too.


Re: [HELP] How to return to float? - paytas - 29.07.2009

You can return floats by adding the Float tag to the function name.

pawn Код:
//incorrect:
stock ReturnFloat()
  return 1.23456;

//correct:
stock Float:ReturnFloat()
  return 1.23456;



Re: [HELP] How to return to float? - afei - 29.07.2009

you may use this
Код:
floatround()



Re: [HELP] How to return to float? - arnutisz - 29.07.2009

But I have:
pawn Код:
stock sGetFloat(filename[], string[])
{
    new filestring[256];
    new fromline[128][2];
    new File:newfile;
  new Float:value;
    newfile = fopen(filename, io_read);
    if(!newfile)
    {
        print("file not found");
        return floatround(value);
    }
    while(fread(newfile, filestring))
    {
        if(!strcmp(string, filestring, true, strlen(string)) && (filestring[strlen(string)] == '='))
        {
            split(filestring, fromline, '=');
            value = floatstr(fromline[1]);
            printf("rofl %f", value);
            return floatround(value);
        }
    }
    fclose(newfile);
    return floatround(value);
}
It doesn't work, or I am doing something wrong? It prints right float value in here: "printf("rofl %f", value);", but returns to 1.000


Re: [HELP] How to return to float? - arnutisz - 30.07.2009

Bump


Re: [HELP] How to return to float? - -Sneaky- - 30.07.2009

Never tried it before, but try this:

pawn Код:
forward Float:asd();
public Float:asd()
{
  new Float:abc;
  abc = 1337.1337;
  return abc;
}
pawn Код:
printf("%f",asd());



Re: [HELP] How to return to float? - arnutisz - 30.07.2009

Thanks, it worked. But why it don't worked with stock function, only with public?


Re: [HELP] How to return to float? - Joe Staff - 30.07.2009

You could have just made it a regular function
i.e.
[pawn]
myfunction(playerid,bacon)
{
...
}
/[pawn]

But you have to have added "Float:"