SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 29/12/2017, 02:04 PM   #641
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 112
Reputation: 10
Default Re: Today I learned - Share your newly found knowledge!

TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
GaByM is offline   Reply With Quote
Old 29/12/2017, 02:23 PM   #642
whadez
Big Clucker
 
whadez's Avatar
 
Join Date: Jun 2014
Location: Hungary
Posts: 119
Reputation: 21
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
ayylmao xd
__________________
Reference:
(Laravel, Vue.js, NuxtJS SSR, JWT) LS:RP - Hungary [Click Here]
(Laravel, Vue.js) RC:RP [Click Here]
(Laravel, Vue.js) LS:RP MTA [Click Here]
(Laravel) LimeGaming MTA [Click Here]
(Laravel) Blue Lake Roleplay [Click Here]

I'm willing to take webdevelopment jobs. Contact me for info.
Discord: whadez#4817
whadez is offline   Reply With Quote
Old 30/12/2017, 08:12 PM   #643
adri1
Banned
 
Join Date: Oct 2010
Posts: 1,779
Reputation: 965
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that all +18yo people that play samp smoke weed
(at least 90% according to my calculations)
adri1 is offline   Reply With Quote
Old 31/12/2017, 09:25 AM   #644
Dutheil
Gangsta
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 507
Reputation: 221
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that using the switch statement slow down compilation time A LOT if used with many cases. I went from compiling my script in 8-15s to 200+
https://pastebin.com/jHf6MyU0
Raw : https://pastebin.com/raw/jHf6MyU0

With the latest version of the Zeex's PAWN Compiler.
Code:
Pawn compiler 3.10.4	 	 	Copyright (c) 1997-2006, ITB CompuPhase

[Finished in 0.5s]
__________________
#PrayForFrenchForum
GitHub

pawn Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});

Last edited by Dutheil; 31/12/2017 at 10:41 AM.
Dutheil is offline   Reply With Quote
Old 03/01/2018, 06:52 AM   #645
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 112
Reputation: 10
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Dutheil View Post
https://pastebin.com/jHf6MyU0
Raw : https://pastebin.com/raw/jHf6MyU0

With the latest version of the Zeex's PAWN Compiler.
Code:
Pawn compiler 3.10.4	 	 	Copyright (c) 1997-2006, ITB CompuPhase

[Finished in 0.5s]
Yes, but I did this:

HTML Code:
#include <a_samp>


main()
{
	new b;
	switch(b)
	{
		case 0..20000: {}
		case 20001..115000: {}
		case 115001..200000: {}
		default: {}
	}
}
Which could be so nicely divided by 5000 or 10000, but who would have thought 3 lines of code can take so much to compile?

Last edited by GaByM; 03/01/2018 at 10:11 AM.
GaByM is offline   Reply With Quote
Old 03/01/2018, 07:25 AM   #646
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,508
Reputation: 305
Default Re: Today I learned - Share your newly found knowledge!

Do you even think some one would do that? And if you're doing it, are you actually using it for something useful or it's just an assumption of a code and you compiled it to check something?

Awaiting response.
Logic_ is offline   Reply With Quote
Old 03/01/2018, 09:52 AM   #647
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 112
Reputation: 10
Default Re: Today I learned - Share your newly found knowledge!

Yes, I use this kind of switch for my fishing system:
Code:
switch(b/10000)
{
	case 0, 1: a = (strcat(s, "some turtles"))*0 + COL_GREY;
	case 2..21: a = (strcat(s, "some fish"))*0 + COL_INFO;
	case 22..39: a = (strcat(s, "a shark"))*0 + COL_BLUE;
	default: a = (strcat(s, "a whale!"))*0 + COL_CYAN;
}
format(str, sizeof(str), "Congratulations! You have caught %s (%i kg). (%i/100 full)", s, b/5000, q);
SCM(playerid, a, str);
Why not an 'if else' block? 2..21 is more readable than (1 < b < 22)

Why do I work with so big numbers in the first place?
'b' means how much volume ocupies the caught fish (since you fish on a boat, your fish fills the boat's boot; every boat has other capacities of storage) measured in cubic centimeters. Why? For reference.

At the moment, I copy other server's economy so I won't place an ad for $50 and eat a burger for $1000.
For example: If a rare fish (a shark) is worth $200,000; on my server, that would be a 200,000cm^3 fish (worth $5,000)
A normal fish (some fish) is worth at least $20,000 and on my server is a 20,000cm^3 fish (worth $500)
GaByM is offline   Reply With Quote
Old 03/01/2018, 06:22 PM   #648
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,508
Reputation: 305
Default Re: Today I learned - Share your newly found knowledge!

No, you don't use this kind of switch for your fishing system, and it's stupid if you do it in this manner to me. This means that the code you've made is not efficient and friendly. I can be wrong but you should post more of your system and ask for suggestions in scripting help.
Logic_ is offline   Reply With Quote
Old 03/01/2018, 06:42 PM   #649
ThePhenix
Gangsta
 
ThePhenix's Avatar
 
Join Date: May 2012
Posts: 801
Reputation: 157
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
Yes, but I did this:

HTML Code:
#include <a_samp>


main()
{
	new b;
	switch(b)
	{
		case 0..20000: {}
		case 20001..115000: {}
		case 115001..200000: {}
		default: {}
	}
}
Which could be so nicely divided by 5000 or 10000, but who would have thought 3 lines of code can take so much to compile?
If you're going to check for ranges you should use "if, elseif, else" instead.
ThePhenix is offline   Reply With Quote
Old 04/01/2018, 04:42 PM   #650
admantis
High-roller
 
Join Date: Sep 2009
Posts: 2,524
Reputation: 449
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Logic_ View Post
No, you don't use this kind of switch for your fishing system, and it's stupid if you do it in this manner to me. This means that the code you've made is not efficient and friendly. I can be wrong but you should post more of your system and ask for suggestions in scripting help.
Please do constructive criticism by posting a better way to do it instead of just saying that's a stupid way to do it.
admantis 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 211 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 02:41 AM.


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