[Solved] How to return to float?
#1

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.
Reply
#2

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;
Reply
#3

you may use this
Код:
floatround()
Reply
#4

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
Reply
#5

Bump
Reply
#6

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());
Reply
#7

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

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

But you have to have added "Float:"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)