1 Warning
#1

Код:
C:\Users\Hash\Desktop\Elite 0.3b\gamemodes\EliteRP.pwn(44539) : warning 208: function with tag result used before definition, forcing reparse
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:           9844 bytes
Code size:          1748416 bytes
Data size:         35699768 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:37474412 bytes

1 Warning.
This is the code

Код:
Float:randomEx(randval)
{
	new rand1 = random(2), rand2;
	return float(rand1 == 0 ? rand2 - random(randval) : rand2 + random(randval));
}
Reply
#2

Forward it :P.
Reply
#3

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
Forward it :P.
It's not required to forward that
Reply
#4

Quote:
Originally Posted by Jakku
Посмотреть сообщение
It's not required to forward that
Orly? Please inform me why its giving this error then .


If you want to fix it, you have 2 options. The first is to forward it, the second is to move the function to the top of the script, before any callbacks (well, any that use this function at least).


EDIT:

here's the forward in-case you have no idea what i am talking about (place it on top of your script) :


Код:
forward Float:randomEx(randval);
Reply
#5

Testing them
Reply
#6

Quote:
Originally Posted by Mouse2426
Посмотреть сообщение
The first is to forward it, the second is to move the function to the top of the script,


if u put it at the top it wil give stack error..

just use a stock and put it below ongamemodeinit..
Ok dont listen to this guy, he is blowing smoke out of his ass and has NO idea what he's doing.


Let me explain WHY stock wont work in this case. Stocks are just like public declarations, except they do not get included if they are not used (also they do not need forwarding unlike publics). The reason why we are forwarding in this case is because a tag is involved (Float, which is a strong tag). The forward serves as a "heads up" to the compiler that a tag is coming its way.

As for your comment on a stack error, this is the result of bad coding and has NOTHING to do with function placement at all (as long as the function is outside of any callbacks/other functions, it is completely valid).



Test this yourself if you dont believe me. Try including my forward, then comment it out and try his method. If you dont want to forward it move it to the top of your script like i said...watch NOTHING different happen :P.
Reply
#7

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
Orly? Please inform me why its giving this error then .


If you want to fix it, you have 2 options. The first is to forward it, the second is to move the function to the top of the script, before any callbacks (well, any that use this function at least).


EDIT:

here's the forward in-case you have no idea what i am talking about (place it on top of your script) :


Код:
forward Float:randomEx(randval);

Correct, Had to forward it, thanks
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
I see someone's been reading their documentation! That makes me very happy!

If anyone cares, here's a little more explanation as to WHY the forward is required. In PAWN everything has the same type (32 bit cell), however you can treat some variables differently using tags. Floats have the "Float" tag, true and false have the "bool" tag. "Float" starts with a capital so is strong, "bool" doesn't so is weak. Strong tags can only be stored in variables with the right tag, weak tags can be stored in any weak tag variable:

pawn Код:
new a = false; // Works.
new Float:a = false; // Shoulsn't work but does - see below.
Note that the default tag, the tag of everything with no specified tag is "_:".

PAWN actually has operator overloading - I bet very few of you knew that! So you can do:

pawn Код:
stock Moo:operator+(Moo:a, Moo:b)
{
    return Moo:(_:a * 2 + _:b * 2);
}
Now if you do:

pawn Код:
new Moo:c = Moo:3 + Moo:4;
You will get 14, not 7.

Now if you look in float.inc you will see a whole load of overloaded operators, including this one:

pawn Код:
native Float:operator=(oper) = float;
Don't worry about the syntax, it uses a feature called internal/external names (another thing I bet you didn't know), but it means doing this will work:

pawn Код:
new a = 5, Float:b = a;
a has tag "_:", b has tag "Float:". This shouldn't work but the overloaded "=" operator, which takes a variable of tag "_:" and returns a variable of tag "Float:" means that the compiler knows how to convert the two - this will compile as:

pawn Код:
new _:a = 5, Float:b = float(a);
Now imagine this code:

pawn Код:
new Float:b = moo();
The compiler has no information about the function "moo" yet, so it generates this code:

pawn Код:
new Float:b = float(moo());
Then later on in your code you have:

pawn Код:
Float:moo() return 10.0;
Now the compiler knows that the "moo" function returns a "Float:" tag value, which means the code above using "float()" to convert from a float is wrong - hence the reparse. As Kyosaur said there are two ways to fix this. The first is to put the "moo" function before where it is used so that the compiler knows it returns a "Float:" tag, the second is to forward the function - again so the compiler knows it returns a "Float:", it just doesn't yet know what it does.
Wow, really nice post!

I dont even think the pawn language guide went into as much detail as you just did lol (its been a while since i read this part tbh). Thanks for taking the time to explain this .

I knew about overloading operators (I think you're the one who wrote the article on the wiki regarding this actually?), but this my first time hearing about internal/external names (i've seen you use this for "mirroring" unformat to sscanf, but thats really about it), pretty cool stuff.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)