Raised This Month: $ Target: $400
 0% 

how to return array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
0920357689
Senior Member
Join Date: Apr 2008
Old 07-21-2012 , 13:59   how to return array
Reply With Quote #1

PHP Code:
...
{
    new 
num[5]
    
get_num(num)
}
stock / public? get_num(?)
{
    for(new 
i=0i<5I++)
        
num i;
    ...?

how to return array?

Last edited by 0920357689; 07-21-2012 at 14:00.
0920357689 is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-21-2012 , 15:05   Re: how to return array
Reply With Quote #2

Code:
public getArray(iNum, output[])
{
    for(new i = 0; i < sizeof output; i++)
        output[i] = --iNum
}
will return an arrray. You have to put it in the paramaters, and it will be passed as a pointer.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 07-21-2012 , 15:38   Re: how to return array
Reply With Quote #3

Quote:
Originally Posted by Liverwiz View Post
Code:
public getArray(iNum, output[])
{
    for(new i = 0; i < sizeof output; i++)
        output[i] = --iNum
}
will return an arrray. You have to put it in the paramaters, and it will be passed as a pointer.
not work
PHP Code:
new NumABC Get_Num(Num)
client_print_color(0TextColor"%d"ABC);

public 
Get_Num(Num)
{
    
Num99;

the num show "0"

Last edited by 0920357689; 07-21-2012 at 15:41.
0920357689 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-21-2012 , 15:40   Re: how to return array
Reply With Quote #4

Num is not an array. If you want to do that, you must use
public Get_Num(&Num)
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 07-21-2012 , 15:48   Re: how to return array
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
Num is not an array. If you want to do that, you must use
public Get_Num(&Num)
i know is not array.....

add & not work too....why?
still show "0"


and use #2 core show
indeterminate array size in "sizeof" expression (symbol "")
send array work. but can't send num...

Last edited by 0920357689; 07-21-2012 at 15:54.
0920357689 is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 07-21-2012 , 15:56   Re: how to return array
Reply With Quote #6

sorry....is my core Problem
now is work...thx for help
0920357689 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-21-2012 , 15:58   Re: how to return array
Reply With Quote #7

Quote:
Originally Posted by 0920357689 View Post
i know is not array.....

add & not work too....why?
still show "0"


and use #2 core show
indeterminate array size in "sizeof" expression (symbol "")
send array work. but can't send num...
Because you don't return anything (which will default to 0). You have to do one of the following:

Code:
new iValue;
GetNum(iValue);
// iValue will be 99

stock GetNum(&iNum)
{
	iNum = 99;
}
or

Code:
new iValue;
iValue = GetNum();
// iValue will be 99

stock GetNum()
{
	return 99;
}
__________________

Last edited by fysiks; 07-21-2012 at 15:59.
fysiks is offline
0920357689
Senior Member
Join Date: Apr 2008
Old 07-21-2012 , 16:28   Re: how to return array
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
Because you don't return anything (which will default to 0). You have to do one of the following:

Code:
new iValue;
GetNum(iValue);
// iValue will be 99

stock GetNum(&iNum)
{
	iNum = 99;
}
or

Code:
new iValue;
iValue = GetNum();
// iValue will be 99

stock GetNum()
{
	return 99;
}
no my core is
num + array

PHP Code:
public Get_Num(&numnum_array[]) 
now work
0920357689 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-21-2012 , 16:40   Re: how to return array
Reply With Quote #9

Well it's nice of you to not explain anything correctly and expect help.

My post is still accurate.
__________________

Last edited by fysiks; 07-21-2012 at 16:41.
fysiks 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 21:32.


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