SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 15/09/2018, 02:46 PM   #11
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 405
Reputation: 31
Default Re: Minimizing lines

Yes but not only if() statements need to be wrapped. EG use a function, to wrap the text you will need to use the "\".
v1k1nG is offline   Reply With Quote
Old 15/09/2018, 02:49 PM   #12
UFF
Huge Clucker
 
UFF's Avatar
 
Join Date: Feb 2018
Location: Funky World
Posts: 338
Reputation: 28
Default Re: Minimizing lines

I wonder, why people replying on the post which has been solved.
__________________
(¯`·._.·Ultimate Funky Freeroam._.·´¯)

Server IP: Closed, We will come back soon!


We also request players to join YSF!
Young Society Freeroam - SonnyGamer's Server

UFF is online now   Reply With Quote
Old 15/09/2018, 02:53 PM   #13
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 405
Reputation: 31
Default Re: Minimizing lines

I wonder why are you so redundant? That solution isn't the most efficient, instead of wasting time stalking forum users and dancing on their nerves, go code, learn something, this forum ain't yours.
Reply only if you have a better solution please.
v1k1nG is offline   Reply With Quote
Old 15/09/2018, 05:16 PM   #14
ShihabSoft
Banned
 
Join Date: Jun 2016
Posts: 163
Reputation: 8
Default Re: Minimizing lines

Quote:
Originally Posted by v1k1nG View Post
I wonder why are you so redundant? That solution isn't the most efficient, instead of wasting time stalking forum users and dancing on their nerves, go code, learn something, this forum ain't yours.
Reply only if you have a better solution please.
Well said!
ShihabSoft is offline   Reply With Quote
Old 16/09/2018, 01:38 AM   #15
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,036
Reputation: 519
Default Re: Minimizing lines

Quote:
Originally Posted by UFF View Post
Please read replies before replying.
Just because a problem is solved, it doesn't mean it can't be improved...

If anyone's reply on this thread is considered 'useless' to you, it should be your own.

I personally would also use a 'switch' in this instance. So pull the stick out of your ass and try and contribute to the community in some form other than being the village idiot.
__________________

Kar's Cops and Robbers 2018
Threshold is offline   Reply With Quote
Old 16/09/2018, 11:36 AM   #16
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,305
Reputation: 3191
Default Re: Minimizing lines

Quote:
Originally Posted by NealPeteros View Post
So I have a crapload of information in one line. How do you minimize it in order to avoid the
Code:
error 075: input line too long (after substitutions)
Code:
if(i != 19 || i != 20 || i != 21 || i != 23 || i != 24 || i != 25 || i != 27 || i != 28 || i != 29 || i != 30 || i != 31 || i != 33 \
                    || i != 34 || i != 35 || i != 36 || i != 37 || i != 38 || i != 39 || i != 40 || i != 41 || i != 42 ||  i != 44 || i != 45 || i != 46 \
                    || i != 47 || i != 48 || i != 49 || i != 50 || i != 51 || i != 52 || i != 53 || i != 55 || i != 56 || i != 57 || i != 58 || i != 59 \
                    || i != 60 || i != 61 || i != 62 || i != 63 || i != 64 || i != 65 || i != 66 || i != 68 || i != 69 || i != 70 \
                    || i != 72 || i != 73 || i != 74 || i != 76 || i != 77 || i != 78)
OK, firstly I don’t think that code does what you think it does. Taking just a small part:

Code:
if(i != 19 || i != 20)
So if the value is 19, the first check fails. But if the value is 19 the second check PASSES! So since you check that a number is not two numbers, every number passes - because no number is two numbers! Of course in your code it is worse since you check many many numbers pointlessly. To pass this check i would have to be 19 AND 20 AND 21 AND … ALL AT ONCE - it clearly can’t be that…

You probably want:

Code:
if (i == 19 || i == 20 || i == 21 ...)
You can then invert the whole thing with ! or else:

Code:
if (!(i == 19 || i == 20 || i == 21 ...))
Secondly, the two given options so far can be combined. They were:

Code:
if (i < 19 || i > 78)
That misses 22, 26, and others.

Code:
switch (i)
{
    case 19, 20, 21, 23, 24, 25, 27, 28, 29, 30, 31, 33, 34,
         35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48,
         49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 61, 62,
         63, 64, 65, 66, 68, 69, 70, 72, 73, 74, 76, 77, 78:
    {
    }
}
That is more accurate and slightly faster than all the ifs, but is fundamentally the same thing.

Code:
switch (i)
{
    case 19..21, 23..25, 27..31, 33..42, 44..53, 55..66, 68..70, 72..74, 76..78:
    {
    }
}
This generates identical code to the other switch, but is a bit shorter to write, and lends itself to a new form:

Code:
if (19 <= i <= 21 || 23 <= i <= 25 || 27 <= i <= 31 || 33 <= i <= 42 || 44 <= i <= 53 || 55 <= i <= 66 || 68 <= i <= 70 || 72 <= i <= 74 || 76 <= i <= 78)
{
}
That’s the fastest method so far given, but there is one even better method no-one has suggested, one that requires just one check (maybe two):

Code:
static const isIn_s[] = {
    false, false, false, false, false, false, false, false, false, false,
    false, false, false, false, false, false, false, false, false, true,
    true,  true,  false, true,  true,  true,  false, true,  true,  true,
    true,  true,  false, true,  true,  true,  true,  true,  true,  true,
    true,  true,  true,  false, true,  true,  true,  true,  true,  true,
    true,  true,  true,  true,  false, true,  true,  true,  true,  true,
    true,  true,  true,  true,  true,  true,  true,  false, true,  true,
    true,  false, true,  true,  true,  false, true,  true,  true
};
if (0 <= i < sizeof (isIn_s) && isIn_s[i])
{
}
The 0 <= i < sizeof (isIn_s) check can be skipped if you know the range of i.
Y_Less 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
will long lines in script 100k lines slow down gamemode PSYCHOBABYKILLA Server Support 2 25/04/2015 12:31 PM
GTA SA keeps minimizing when using SA-MP Jack Shred Client Support 8 07/04/2012 12:40 AM
GTA Minimizing itself?!? NotoriousMOB General 2 03/04/2011 10:46 PM
Problem with minimizing DamiRocK Client Support 2 25/10/2009 07:11 PM
Minimizing Problem Questioner Client Support 4 13/08/2009 02:28 AM


All times are GMT. The time now is 01:32 PM.


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