SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 26/01/2011, 02:04 PM   #11
ipsBruno
Godfather
 
ipsBruno's Avatar
 
Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
Default Respuesta: Tips & Tricks

Good Work Slice :3

But use ++i and not i++...

Great Tutorial!
__________________
Baixar Músicas Grátis
ipsBruno is offline   Reply With Quote
Old 26/01/2011, 02:14 PM   #12
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,899
Reputation: 1589
Default Re: Respuesta: Tips & Tricks

Quote:
Originally Posted by [FeK]DraKiNs View Post
Good Work Slice :3

But use ++i and not i++...

Great Tutorial!
++x and x++ statements that aren't inside anything are exactly the same thing in PAWN. If the value is used, the only difference is that 2 assembly instructions happen in a different order.
Slice is offline   Reply With Quote
Old 26/01/2011, 02:39 PM   #13
Hiddos
High-roller
 
Hiddos's Avatar
 
Join Date: Sep 2008
Posts: 4,844
Reputation: 2179
Default Re: Tips & Tricks

I've been using the ternary operator for quite some time now (Can be found in my turtle/cow scripts for those who looked at the source), it's really great. Something else what is fun to do with it is to make complex code (Preferably a ternary operator inside a ternary operator), then break your head on what is actually stated haha.

I didn't knew about the char arrays either, I'm sure to use this in the future along with other functions.
__________________
Quote:
Originally Posted by DeWolf View Post
For fuck's sake people, this whole thread is fucked up now.
Hiddos is offline   Reply With Quote
Old 26/01/2011, 02:50 PM   #14
Trooper[Y]
Gangsta
 
Trooper[Y]'s Avatar
 
Join Date: Apr 2009
Posts: 514
Reputation: 18
Default Re: Tips & Tricks

just watched your "fastest loops" section -
still too long, the steps that make you feel good
are useless, you can directly do i < GetMaxPlayers() f.e.
__________________




Trooper[Y] is offline   Reply With Quote
Old 26/01/2011, 02:53 PM   #15
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,899
Reputation: 1589
Default Re: Tips & Tricks

@Hiddos:
Code:
for(new i,s[64];i<10;i++)strcat(s,!i?("The"):i<2?("quick"):i<3?("brown"):i<4?("fox"):i<5?("jumps"):i<6?("over"):i<7?("the"):i<8?("lazy"):i<9?("dog."):i<printf(s)?(""):("")),strcat(s," ");
wat


Quote:
Originally Posted by Trooper[Y] View Post
just watched your "fastest loops" section -
still too long, the steps that make you feel good
are useless, you can directly do i < GetMaxPlayers() f.e.
Oh and call GetMaxPlayers every iteration? You do that!
Slice is offline   Reply With Quote
Old 26/01/2011, 05:23 PM   #16
Hiddos
High-roller
 
Hiddos's Avatar
 
Join Date: Sep 2008
Posts: 4,844
Reputation: 2179
Default Re: Tips & Tricks

Quote:
Originally Posted by Slice View Post
@Hiddos:
Code:
for(new i,s[64];i<10;i++)strcat(s,!i?("The"):i<2?("quick"):i<3?("brown"):i<4?("fox"):i<5?("jumps"):i<6?("over"):i<7?("the"):i<8?("lazy"):i<9?("dog."):i<printf(s)?(""):("")),strcat(s," ");
Code:
for(new i, s[64]; i < 10; i++)
{
	if(!i) strcat(s, "The"), strcat(s, " ");
	else if(i < 2) strcat(s, "quick"), strcat(s, " ");
	else if(i < 3) strcat(s, "brown"), strcat(s, " ");
	else if(i < 4) strcat(s, "fox"), strcat(s, " ");
	else if(i < 5) strcat(s, "jumps"), strcat(s, " ");
	else if(i < 6) strcat(s, "over"), strcat(s, " ");
	else if(i < 7) strcat(s, "the"), strcat(s, " ");
	else if(i < 8) strcat(s, "lazy"), strcat(s, " ");
	else if(i < 9) strcat(s, "dog."), strcat(s, " ");
	else if(i < printf(s)) strcat(s, ""), strcat(s, " ");
	else strcat(s, ""), strcat(s, " ");
}

Did a test, it worked. I'm a genius.
I also found this in some code of a script of mine. It unfortunately did not work. I'm still thinking of disassembling it once ^^.

Code:
Pos[0] += ((Keys[2] > 0) ? ((Keys[0] & KEY_SPRINT) ? ((Keys[0] & KEY_JUMP) ? (5.4) : (3.6)) : ((Keys[0] & KEY_JUMP) ? (2.7) : (1.8))) : (Keys[2] < 0) ? ((Keys[0] & KEY_SPRINT) ? ((Keys[0] & KEY_JUMP) ? (-5.4) : (-3.6)) : ((Keys[0] & KEY_JUMP) ? (-2.7) : (-1.8))) : (0.0));
Good luck if anyone feels like trying it. The ( ) should be of much help ^^.
Quote:
Originally Posted by Slice View Post
Oh and call GetMaxPlayers every iteration? You do that!
Hmm, doesn't sound like a perfect method ^^.
__________________
Quote:
Originally Posted by DeWolf View Post
For fuck's sake people, this whole thread is fucked up now.
Hiddos is offline   Reply With Quote
Old 26/01/2011, 05:32 PM   #17
ipsBruno
Godfather
 
ipsBruno's Avatar
 
Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
Default Respuesta: Tips & Tricks

@Trooper[Y]
What?

Code:
for(new i; i < GetMaxPlayer(); ++i)
is not otimized,lol

@Slice
I know what
i++ keeping the value in memory, and only applies to the variable after the instruction has been executed, the ++i apply at the time of instruction without storing in memory.

Not?
__________________
Baixar Músicas Grátis
ipsBruno is offline   Reply With Quote
Old 26/01/2011, 05:38 PM   #18
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,899
Reputation: 1589
Default Re: Respuesta: Tips & Tricks

@Hiddos:
Put this in a FS and load it.
Code:
#include <a_samp>

public OnFilterScriptInit()
for(new c[]="osudrlnfaYAI tvciy'mW\ngwehk",i=2,s[146],y[2];i>1;i++)
y[0]=c[i<3?21:i<4?21:i<5?21:i<6?20:i<7?24:i<8?18:i<9?4:i<10?24:i<11?12:i<12?6:i<13?0:i<14?12:i<15?1:i<16?13:i<17?4:i<18?8:i<19?6:i<20?22:i<21?24:i<22?4:i<23?1:i<24?12:i<25?13:i<26?0:i<27?12:i<28?5:i<29?0:i<30?14:i<31?24:i<32?21:i<33?9:i<34?0:i<35?2:i<36?12:i<37?26:i<38?6:i<39?0:i<40?23:i<41?12:i<42?13:i<43?25:i<44?24:i<45?12:i<46?4:i<47?2:i<48?5:i<49?24:i<50?1:i<51?12:i<52?8:i<53?6:i<54?3:i<55?12:i<56?1:i<57?0:i<58?12:i<59?3:i<60?0:i<61?12:i<62?11:i<63?21:i<64?10:i<65?12:i<66?7:
i<67?2:i<68?5:i<69?5:i<70?12:i<71?15:i<72?0:i<73?19:i<74?19:i<75?16:i<76?13:i<77?19:i<78?24:i<79?6:i<80?13:i<81?18:i<82?1:i<83?12:i<84?23:i<85?25:i<86?8:i<87?13:i<88?12:i<89?11:i<90?18:i<91?19:i<92?12:i<93?13:i<94?25:i<95?16:i<96?6:i<97?26:i<98?16:i<99?6:i<100?22:i<101?12:i<102?0:i<103?7:i<104?21:i<105?9:i<106?0:i<107?2:i<108?12:i<109?23:i<110?0:i<111?2:i<112?5:i<113?3:i<114?6:i<115?18:i<116?13:i<117?12:i<118?22:i<119?24:i<120?13:i<121?12:i<122?13:i<123?25:i<124?16:i<125?1:
i<126?12:i<127?7:i<128?4:i<129?0:i<130?19:i<131?12:i<132?8:i<133?6:i<134?17:i<135?12:i<136?0:i<137?13:i<138?25:i<139?24:i<140?4:i<141?12:i<142?22:i<143?2:i<144?17:i<145?21:i<146?21:i<147?21:print(s)?(i=0):(i=0)],strcat(s,y);
Win.

Also, I broke down your ternary and noticed an error that I fixed - try this:
Code:
Pos[0] +=
	(
		( Keys[2] > 0 )
		? (
			( Keys[0] & KEY_SPRINT )
			? (
				( Keys[0] & KEY_JUMP )
					? ( 5.4 )
					: ( 3.6 ) )
			: (
				( Keys[0] & KEY_JUMP )
					? ( 2.7 )
					: ( 1.8 ) )
		)
		: (
			( Keys[2] < 0 )
			? (
				( Keys[0] & KEY_SPRINT )
				? (
					( Keys[0] & KEY_JUMP )
					? ( -5.4 ) : ( -3.6 ) )
				: (
					(Keys[0] & KEY_JUMP)
					? ( -2.7 ) : ( -1.8 ) )
			)
			: ( 0.0 )
		)
	)
;

@[FeK]DraKiNs:
In PAWN it's different, there's no difference in speed if you're using ++i or i++ and using its value - there is a slight difference in the resulting assembly code, though.
If you're not using the value from the variable you're incrementing (like in a for loop), ++i and i++ are the exact same things.

Code:
for ( new i = 0, l = strlen( string ); i != l; i++ )
Is exactly the same as:
Code:
for ( new i = 0, l = strlen( string ); i != l; ++i )

If you don't believe me, run the PAWN compiler with the additional -a in the command line to see the assembly output.
Slice is offline   Reply With Quote
Old 26/01/2011, 05:41 PM   #19
ipsBruno
Godfather
 
ipsBruno's Avatar
 
Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
Default Respuesta: Tips & Tricks

i believe you :3
is that we're used to other languages ..
But Thanks Slice

Sorry my English
__________________
Baixar Músicas Grátis
ipsBruno is offline   Reply With Quote
Old 26/01/2011, 05:55 PM   #20
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 3,983
Reputation: 1587
Default Re: Tips & Tricks

gnagnagna Hiddos and Slice are doing the most funny match ever: The script match
Never heard of it untill now.

And @Hiddos ("I'm a genius"):
And you're soooo modest xD (bescheiden)...
NOT! :P
__________________
Assassin's Creed: SAMP website: www.acsamp.com
Mail: kwarde@acsamp.com

Latest 3 changelogs of ACSAMP
Code:
25/02/2018 17:19 - Added Actors in (the renewed) Abstergo (v0.1.122-A)
25/02/2018 17:37 - Added introduction route (dialogs not yet added) (v0.1.123-A)
26/02/2018 17:28 - Map improvements, introduction/tutorial stuff added, weird map bug fixed (v0.1.127-A)
Kwarde 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
Needs Scripting Tips! KomplettMaster General 12 26/12/2012 04:04 PM
[Tutorial] [InfiniTuts - Tutorials for beginners] Tips and Tricks regarding 'logical thinking' - Making your own script Infinity Tutorials 6 29/04/2012 11:34 PM
Motor Tricks by D12 D12Mr Screenshots and Videos 6 24/05/2009 06:04 PM


All times are GMT. The time now is 02:49 PM.


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