Procedure defaults

Just starting out? Need help? Post your questions and find answers here.
User avatar
Piero
Addict
Addict
Posts: 1240
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Procedure defaults

Post by Piero »

Is this possible in some easy way?

Code: Select all

Procedure p(a=1, b=1, c=1)
   ProcedureReturn a + b + c
EndProcedure

Debug p(#PB_Ignore, #PB_Ignore, 0) ; should return 2
User avatar
ChrisR
Addict
Addict
Posts: 1595
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Procedure defaults

Post by ChrisR »

Code: Select all

Debug "#PB_Ignore = " + #PB_Ignore
#PB_Ignore = -65535
-65535+(-65535)+0=-131070 (not 2)
User avatar
Piero
Addict
Addict
Posts: 1240
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Procedure defaults

Post by Piero »

Thanks, I know; I could have used #PB_Default too :D
I WANT to get 2 as result! :shock:
miso
Enthusiast
Enthusiast
Posts: 721
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Procedure defaults

Post by miso »

Edit, ( I dont understand why would this function be used with #pb_any, as its value can change. Last time I remember #pb ignore was -1 in value...)
Edit2: pb any was and is -1... Until Fred decides to be otherwise.

Code: Select all


Procedure.i p(a.b=1, b.b=1, c.b=1)
   ProcedureReturn a + b + c
EndProcedure

Debug p(#PB_Ignore, #PB_Ignore, 0) ; should return 2


;ivalue.i = #PB_Ignore
;Debug #PB_Ignore
;Debug ivalue


Last edited by miso on Thu Mar 12, 2026 3:42 am, edited 2 times in total.
User avatar
ChrisR
Addict
Addict
Posts: 1595
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Procedure defaults

Post by ChrisR »

You could also have tried #PB_Any or #PB_All to show that they don't work either :wink:
It works with the byte initialized as miso did, or with a.u=1...

For fun :lol:

Code: Select all

#PB_Ananas = 1

Procedure pizza(a, b, c)
   ProcedureReturn a + b + c
EndProcedure

Debug pizza(#PB_Ananas, #PB_Ananas, 0) ; return 2
User avatar
Piero
Addict
Addict
Posts: 1240
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Procedure defaults

Post by Piero »

It would be cool if this worked:

Code: Select all

Macro m(a=0,b=0,c=0)
   Debug a+b+c
EndMacro

m(,1) ; should give 1 (b=1)
SMaag
Enthusiast
Enthusiast
Posts: 388
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: Procedure defaults

Post by SMaag »

Procedure p(a=1, b=1, c=1)
ProcedureReturn a + b + c
EndProcedure

Debug p(#PB_Ignore, #PB_Ignore, 0) ; should return 2
why you want to get 2 as result, what is a wrong result for that operation???

What is your goal to reach?
User avatar
Piero
Addict
Addict
Posts: 1240
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Procedure defaults

Post by Piero »

SMaag wrote: Thu Mar 12, 2026 7:08 amWhat is your goal to reach?
Having optional parameters anywhere, not only at the end of the "parameter list"

viewtopic.php?p=652619#p652619
Post Reply