Page 1 of 1

simplifying procedure calling

Posted: Tue Feb 04, 2025 4:35 pm
by jjarrell
Is there a better way to simplify procedure calls?
As in the example below is use 2 commands to get the result.
Is there a way to do accomplish something like this?

results=rollDice[dice$]

or is the 2 lines I use the best way?

Code: Select all

sTART:
	CLS
	RANDOMIZE TIMER
	
	PROCEDURE rollDice[diceStr$]
		{some code to parse and create a total}
		RETURN total
	END PROC	
	
	INPUT "ENTER DICE TO ROLL. EXAMPLE 3D6 ",dice$
	rollDice[dice$]
	results=PARAM(rollDice)
	PRINT "RESULT = ";results
	PRINT
	PRINT "PRESS ANY KEY TO ROLL AGAIN"
	WAIT KEY RELEASE
GOTO sTART

Re: simplifying procedure calling

Posted: Tue Feb 04, 2025 5:52 pm
by spotlessmind1975
Hi jjfarrell!
jjarrell wrote: Tue Feb 04, 2025 4:35 pm Is there a way to do accomplish something like this?

Code: Select all

results=rollDice[dice$]
Yes, there is.
Just... use it! :D

The ugBASIC language supports both syntaxes.

Re: simplifying procedure calling

Posted: Tue Feb 04, 2025 8:11 pm
by jjarrell
Works like a charm. Thanks.

On p. 113 of the manual I saw "If the procedure returns a value, the calling statement just ignore it." and just assumed you had to go the PARAM route.