Raised This Month: $ Target: $400
 0% 

[Question] Null parameter constant, loop inside a loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-18-2014 , 14:23   [Question] Null parameter constant, loop inside a loop
Reply With Quote #1

Hey, I wanted to ask you here two questions, far far different. I know that on oe thread there should be one topic, but these questions are pretty little and not that improtant (and people here don't like giving PM support, so...) and I thought it would be better to put them in one thread isntead of flooding with useless threads. But anyways, if it's problem, I'll post nother thread.

The first question is if there is some problem with making a loop inside another loop? I'm asking this, beacuse sometimes I want to combine two constants in one and I have to use two loops inside, one inside the other. Giving example:
PHP Code:
new const cmds[][]= 

    
""
    
"hegrenade"
    
"grenade"
    
"he"
    
"gren"
    
"bomb" 


new const 
styles[][]= 

    
""
    
"say "
    
"say /"
    
"say_team "
    
"say_team /" 


new 
string[64

public 
plugin_init() 

        for(new 
1sizeof cmdsi++) 
        { 
            for(new 
1sizeof stylesa++) 
            { 
                 
formatex(stringcharsmax(string), "%s%s"styles[a], cmds[i]) 
                 
register_clcmd(string"hegrenade"
            } 
        } 

Is there any problem with that one?

And the second question I want to know just for information - does living a null parameter in a constant matter with something? I mean, that empty space that is used as a null parameter in the constants so often. I ask this, beacause the arrays also start from index 0, like the constants. Does this null parameter mean with something?
PHP Code:
new const styles[][]= 

    
""//We are talking about that empty parameter here...
    
"say "
    
"say /"
    
"say_team "
    
"say_team " 

Any information is appereciated! Thanks!
__________________

Last edited by Flick3rR; 06-18-2014 at 15:31.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-18-2014 , 14:33   Re: [Question] Null parameter constant, loops
Reply With Quote #2

It's fine to make loops inside loops, however in Pawn, you should consider not creating variables inside loops (in your case the variable a is created inside a loop) to not needlessly re-create them on each iteration.

You don't have to add a null value to the arrays. Since the indexing starts from 0, in the loop you just do new i = 0 (or rather, just new i) instead of = 1 and for the array you just skip the null value: new const array[] = {"value1", "value2", ...}.
__________________

Last edited by hleV; 06-18-2014 at 14:39.
hleV is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-18-2014 , 14:47   Re: [Question] Null parameter constant, loops
Reply With Quote #3

(Uhm, the string is created otside any functions, it's global)
Okay, thanks! Waiting for another opinions, since I've heard many different things about that null parameter.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-18-2014 , 14:52   Re: [Question] Null parameter constant, loops
Reply With Quote #4

"a" is created inside of the first loop.

Start using 0 as the first index. You're wasting memory for no reason.

If you register "say /" it will only match "say /" not, for example, "say /hello".
__________________

Last edited by Black Rose; 06-18-2014 at 14:54.
Black Rose is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-18-2014 , 14:59   Re: [Question] Null parameter constant, loops
Reply With Quote #5

Well, the idea of these loops is the current keyword typed in all the styles. That's why I formatexed them side by side, so all of the keywords will be registered after each style. About that "a", right.
__________________

Last edited by Flick3rR; 06-18-2014 at 15:18.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-18-2014 , 15:10   Re: [Question] Null parameter constant, loops
Reply With Quote #6

Oh right. Sorry.
__________________
Black Rose is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-18-2014 , 15:32   Re: [Question] Null parameter constant, loop inside a loop
Reply With Quote #7

Problems solved, thanks to all these guys! Okay, now for that topics. I don't want to look stupid, but I rather ask you what to do, when obviously there are two topic in one thread here and this is against the rules.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-18-2014 , 16:04   Re: [Question] Null parameter constant, loop inside a loop
Reply With Quote #8

I'm not sure what you're asking.
In some cases it serves a purpose. For example when using an array of strings to convert a weapon index to a weapon name. Since there is not weapon id 0 there's no point of filling that with anything.
And you could of course shift everything by 1 step and use mystringarray[weaponid - 1], but that would just make things complicated for no good reason.
__________________
Black Rose is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-18-2014 , 16:11   Re: [Question] Null parameter constant, loop inside a loop
Reply With Quote #9

I was asking what to do with the problem, that there are two topics in one thread. To delete one of the questions or what? Because it's violating the rules.
Thanks for the information!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Reply



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

Forum Jump


All times are GMT -4. The time now is 11:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode