Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Trouble w/ functions w/ Default Values
Old 10-27-2007, 11:44 AM Trouble w/ functions w/ Default Values
InfinitySchima's Avatar
Skilled Talker

Posts: 71
Name: Rafael Schimassek
Trades: 0
Hi,
I'm having here a problem with a function that uses default values. I declared a function like this:
PHP Code:
function _subtractresources($townid$towntype$wood 0$stone 0$metal 0) { 
As you can see I am using default values on the last three arguments.
Now how can I run the functions while, for example, only putting the townid, towntype and stone arguments? I tried something like this...
PHP Code:
_subtractresources($idtown$typetown, , 300, ) 
I thought of it because you could also do it on a for(;$x < 5; ) .
But it doesn't works, also if I erase the last comma ' , '. Instead I get something like:
Parse error: syntax error, unexpected ',' in C:\My\Path\To\It\some_file.php on line 89.
Can anyone tell me on how to do it? In the last case I fill in all the blank spaces with 0.

Thanks in advance,
Schimassek...

InfinitySchima is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-27-2007, 12:15 PM Re: Trouble w/ functions w/ Default Values
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
PHP Code:
_subtractresources($idtown$typetown0300); 
You just have to enter in the default value for any skipped parameters.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-28-2007, 09:26 AM Re: Trouble w/ functions w/ Default Values
InfinitySchima's Avatar
Skilled Talker

Posts: 71
Name: Rafael Schimassek
Trades: 0
sure, thanks for the info.

Schimassek...
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Old 10-29-2007, 06:00 AM Re: Trouble w/ functions w/ Default Values
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You may also create wrapper functions for each resource type and call your existing function from it with right arguments:
PHP Code:
function subtract_wood($town_id$town_type$value) {
   
_subtractresources($town_id$town_type$value);
}
function 
subtract_stone($town_id$town_type$value) {
   
_subtractresources($town_id$town_type0$value);

__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Trouble w/ functions w/ Default Values
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13997 seconds with 12 queries