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, 04:49 PM   #701
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 111
Reputation: 7
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, 12:05 PM   #702
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 292
Reputation: 126
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, 06:30 PM   #703
AgusZ
Big Clucker
 
AgusZ's Avatar
 
Join Date: Nov 2014
Posts: 145
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)
__________________
AgusZ is offline   Reply With Quote
Old 07/11/2017, 06:35 PM   #704
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,259
Reputation: 227
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
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning


Eoussama is offline   Reply With Quote
Old 17/11/2017, 07:24 PM   #705
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,897
Reputation: 3126
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 online now   Reply With Quote
Old 17/11/2017, 08:16 PM   #706
Meller
Banned
 
Join Date: Dec 2016
Posts: 638
Reputation: 132
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.
Meller is offline   Reply With Quote
Old 17/11/2017, 09:28 PM   #707
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,897
Reputation: 3126
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 online now   Reply With Quote
Old 24/11/2017, 06:20 PM   #708
Meller
Banned
 
Join Date: Dec 2016
Posts: 638
Reputation: 132
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.
Meller is offline   Reply With Quote
Old 04/12/2017, 05:49 AM   #709
Mobtiesgangsa
Big Clucker
 
Mobtiesgangsa's Avatar
 
Join Date: Oct 2016
Location: Skopje, Macedonia
Posts: 99
Reputation: 9
Default Re: Today I learned - Share your newly found knowledge!

Today i Learned - how to spilt the chat

example

Code:
player (0): blablbaajh
__________________
YSI User

Code:
public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
	switch(success)
	{
	    case COMMAND_UNDEFINED:
	    {
		    TextDrawShowForPlayer(playerid, cmdinfo[playerid]);
		    SetTimerEx("UnknownCommand", 3000, false, "d", playerid);
	    }
	}
	return COMMAND_OK;
}
Mobtiesgangsa is offline   Reply With Quote
Old 18/12/2017, 09:33 PM   #710
PatrickGTR
Little Clucker
 
PatrickGTR's Avatar
 
Join Date: Sep 2010
Location: United Kingdom
Posts: 15
Reputation: 48
Default Re: Today I learned - Share your newly found knowledge!

TIL, that include name collisions is a silent killer, I never got a single error/warning from it on my end (using the updated Zeex's compiler) - The code worked fine nonetheless but when I tried to migrate to sampctl I was recieving tonnes of errors/warnings due to having multiple include names with the same filename such as header.inc, impl.inc and main.inc.

For more information: https://github.com/Misiur/YSI-Includ...Include-Guards
__________________
PatrickGTR 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 07:07 AM
How you learned to script Bam23 Help Archive 9 11/04/2011 10:21 AM
What did u learned today ? rafay Everything and Nothing 170 30/03/2010 04:06 PM


All times are GMT. The time now is 11:58 AM.


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