simplifying procedure calling

This forum is dedicated to those who want support programming in ugBASIC.
Questo forum è dedicato a chi desidera supporto per programmare in ugBASIC.
Ce forum est dédié à ceux qui souhaitent prendre en charge la programmation en ugBASIC.
Post Reply
jjarrell
Posts: 26
Joined: Tue Jan 28, 2025 5:35 pm

simplifying procedure calling

Post 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
spotlessmind1975
Site Admin
Posts: 191
Joined: Fri Oct 06, 2023 8:25 pm

Re: simplifying procedure calling

Post 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.
jjarrell
Posts: 26
Joined: Tue Jan 28, 2025 5:35 pm

Re: simplifying procedure calling

Post 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.
Post Reply