Raised This Month: $ Target: $400
 0% 

const in function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 04-30-2011 , 13:32   const in function
Reply With Quote #1

Hey, how can I add a const parameter in function like:
PHP Code:
new const RandomColors[3][] = {
"255, 0, 0",
"0, 255, 0",
"0, 0, 255"
}

set_dhudmessageRandomColors[random_num(1,3)], 0.030.21212.04.00.22.0 ); 
It says:
Quote:
Error: Argument type mismatch (argument 1)
reinert is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-30-2011 , 13:38   Re: const in function
Reply With Quote #2

I guess Arkshine didn't add const for colors.

BTW change random_num(1, 3) to random(sizeof RandomColors).
__________________
hleV is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-30-2011 , 13:47   Re: const in function
Reply With Quote #3

So is there another way of getting (R,G,B) colors from my list and adding them to set_dhudmessage function ?
reinert is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-30-2011 , 13:51   Re: const in function
Reply With Quote #4

May need to mod the function on your own. I've never seen\used it but:

PHP Code:
new const RandomColors[3][] = 
{
   
"255, 0, 0",
   
"0, 255, 0",
   
"0, 0, 255"
};

public 
YourFunc( const szRGB[] )
{
     
//parse and use colors here
}

//Call function
YourFuncRandomColorsrandomsizeofRandomColors ) ) ] ) 
or

PHP Code:
enum Colors
{
    
Red,
    
Green,
    
Blue
}

new const 
RandomColors][ Colors ] = 
{
    { 
255 },
    { 
255 },
    { 
255 }
};

public 
YourFunc( const iRGBColors ] )
    
server_print"R=%d G=%d B=%d" iRGBRed ] , iRGBGreen ] , iRGBBlue ] );

public 
lols()
    
YourFuncRandomColorsrandomsizeofRandomColors ) ) ] ) 
__________________

Last edited by Bugsy; 04-30-2011 at 13:58.
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-30-2011 , 13:54   Re: const in function
Reply With Quote #5

set_dhudmessage mimic set_hudmessage, meaning the color is not a string.

set_dhudmessage( red, green, blue, ... );
__________________
Arkshine is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-30-2011 , 13:57   Re: const in function
Reply With Quote #6

how can I parse it ?
PHP Code:
new rgb;
parse(RandomColors[random(3)], r,b)

set_dhudmessagerg... ) 
Like this ? But this is not working
reinert is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-30-2011 , 14:08   Re: const in function
Reply With Quote #7

Why working with string ?
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-30-2011 , 14:11   Re: const in function
Reply With Quote #8

- Was said that colors are not string and are 3 different params
- You mis-use parse native
- If you use parse you would have to convert string colors into int colors.

PHP Code:
new const RandomColors[][] = {
    {
25500},
    {
02550},
    {
00255}
}

new 
iRandom randomsizeof(RandomColors) )

set_dhudmessage(RandomColors[0][iRandom],RandomColors[1][iRandom],RandomColors[2][iRandom], 0.030.21212.04.00.22.0 ); 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-30-2011 , 14:14   Re: const in function
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
- Was said that colors are not string and are 3 different params
- You mis-use parse native
- If you use parse you would have to convert string colors into int colors.

PHP Code:
new const RandomColors[][] = {
    {
25500},
    {
02550},
    {
00255}
}

new 
iRandom randomsizeof(RandomColors) )

set_dhudmessage(RandomColors[0][iRandom],RandomColors[1][iRandom],RandomColors[2][iRandom], 0.030.21212.04.00.22.0 ); 
Thanks, that should be good ;)
reinert is offline
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 04:18.


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