SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 18/10/2017, 05:49 PM   #701
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 66
Reputation: 0
Default Re: Today I learned - Share your newly found knowledge!

TIL that

PHP Code:
#include <a_samp>
main()
{
    {
        new 
k;
        new 
bla[3][3];
        new 
z;
        
printf(""kbla[1], z);
    }
    {
        new 
z//ok
        
new bla//not ok, symbol already defined
        
new k//symbol already defined
        
printf(""kblaz);
    }
    return 
1;

the code above won't work

If you declare a matrix then any try of defining a variable(in other scope) with the same name with the ones that are above the matrix won't work
GaByM is offline   Reply With Quote
Old 20/10/2017, 01:05 PM   #702
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 257
Reputation: 65
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that

PHP Code:
#include <a_samp>
main()
{
    {
        new 
k;
        new 
bla[3][3];
        new 
z;
        
printf(""kbla[1], z);
    }
    {
        new 
z//ok
        
new bla//not ok, symbol already defined
        
new k//symbol already defined
        
printf(""kblaz);
    }
    return 
1;

the code above won't work

If you declare a matrix then any try of defining a variable(in other scope) with the same name with the ones that are above the matrix won't work
Use this https://github.com/Zeex/pawn
OneDay is offline   Reply With Quote
Old 04/11/2017, 07:30 PM   #703
AgusZ
Big Clucker
 
AgusZ's Avatar
 
Join Date: Nov 2014
Location: Indonesia
Posts: 135
Reputation: 7
Default Re: Today I learned - Share your newly found knowledge!

Today I Learned I can make a new function without forward.
Quote:
#if !defined function
#define function%0(%1) \
forward%0(%1); public%0(%1)
#endif

Function Time(playerid)
__________________
WKWKWKWKWKWKWKWKWK.
AgusZ is offline   Reply With Quote
Old 07/11/2017, 07:35 PM   #704
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,119
Reputation: 153
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that you can specify more than one tag to variables.
PHP Code:
{Float,_}:something
quoted from http://forum.sa-mp.com/showpost.php?...16&postcount=2
__________________
Eoussama is online now   Reply With Quote
Old 17/11/2017, 08:24 PM   #705
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,537
Reputation: 2938
Default Re: Today I learned - Share your newly found knowledge!

Today I learned you can invert a string. Not any sane definition of "invert", but this:

PHP Code:
Func(arr[])
{
}
main()
{
    
Func(~~"hi");

What does that do? Absolutely nothing! It actually gets the address of the string, inverts it twice (giving the original result) then calls the function. You can't do this for direct assignment though.
Y_Less is offline   Reply With Quote
Old 17/11/2017, 09:16 PM   #706
Meller
Gangsta
 
Meller's Avatar
 
Join Date: Dec 2016
Posts: 605
Reputation: 108
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by AgusZ View Post
Today I Learned I can make a new function without forward.
Just thought I should inform you that you are actually forwarding this callback into a public function. You're just using a macro definition to shorten your code up.




Today I learned that the YSI library has a lot to offer that is more useful than I thought, for examply the y_timers, y_iterates, y_stringhash, y_bit to just name a few.
__________________
#me too
Meller is offline   Reply With Quote
Old 17/11/2017, 10:28 PM   #707
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,537
Reputation: 2938
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by AgusZ View Post
Today I Learned I can make a new function without forward.
Yeah, that's not doing it without forward, just hiding forward in a macro, which is a shame, because you can do it without forward:

PHP Code:
Func();
Func()
{

Is valid - the "forward" keyword can be ommitted (under certain circumstances).
Y_Less is offline   Reply With Quote
Old 24/11/2017, 07:20 PM   #708
Meller
Gangsta
 
Meller's Avatar
 
Join Date: Dec 2016
Posts: 605
Reputation: 108
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that states are a thing in PAWN;
PHP Code:
#include <a_samp>

#define MACRO_FLAG_A (0)
#define MACRO_FLAG_B (1)

new flag = -1;

forward @stateCheck();

main() {
    
state STATE_FLAG_A;
    @
stateCheck();
    
    
flag MACRO_FLAG_A;
    @
stateCheck();

    
flag MACRO_FLAG_B;
    
state STATE_FLAG_B;
    @
stateCheck();
}

@
stateCheck() <STATE_FLAG_A> {
    
printf("@stateCheck says: variable 'flag' are (%i) and stage are static 'STATE_FLAG_A'"flag);
}

@
stateCheck() <STATE_FLAG_B> {
    
printf("@stateCheck says: variable 'flag' are (%i) and stage are static 'STATE_FLAG_B'"flag);

Which outputs
Quote:
@stateCheck says: variable 'flag' are (-1) and stage are static 'STATE_FLAG_A'
@stateCheck says: variable 'flag' are (0) and stage are static 'STATE_FLAG_A'
@stateCheck says: variable 'flag' are (1) and stage are static 'STATE_FLAG_B'
Now this hasn't got a direct useful usage (in this example) but I can surely think of uses of this.
__________________
#me too
Meller is offline   Reply With Quote
Old 04/12/2017, 06:49 AM   #709
Mobtiesgangsa
Little Clucker
 
Mobtiesgangsa's Avatar
 
Join Date: Oct 2016
Location: Skopje, Macedonia
Posts: 27
Reputation: 3
Default Re: Today I learned - Share your newly found knowledge!

Today i Learned - how to spilt the chat

example

Code:
player (0): blablbaajh
__________________
Quote:
The only thing that i have done that is not mitigated by luck,
diminished by good fortune, is that i presisted, and ither people gave up.
Mobtiesgangsa is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Things you learned from GTA SA Toni Everything and Nothing 212 20/08/2011 08:07 AM
How you learned to script Bam23 Help Archive 9 11/04/2011 11:21 AM
What did u learned today ? rafay Everything and Nothing 170 30/03/2010 05:06 PM


All times are GMT. The time now is 07:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.