forums

TNT Basic Forums > Feedback
Procedures
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-28-2005 13:00

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

I need procedures to be able to return more than one variable:


Global Float gravity=0.5,x,y,v
While not pressed(12) 'Q
MoveSprite(x,y,v)
x=newX
y=newY
v=newV

Sprite 0,x,y,0
Wend


Prodedure MoveSprite(float newX, float newY, float newV)
newX=newX+random(-1,1)
newV=newV+gravity
newY=newY+newV
End Proc(float newX, float newY, float newV)

12-13-2005 22:27

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

This is done in other programming languages by use of reference parameters. This are are parameters which if assigned within the procedure, will actually affect the value of the variable passed in from the caller. An example of how this could be implemented in TNT Basic is:

int a=10
MyProc(a)
print a

procedure MyProc(var int x)
x=5
end proc

This would print 5 rather than 10.

No this doesn't work in TB at the moment :) This is just how I believe it should be done, but it requires some work on the TB interpretter to make it possible.

Mark

12-14-2005 00:29

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

But...

Procedures should not, and will not, return multiple parameters 'by value'. 'By reference' means the values must be there to begin with, creating global variables within a procedure is just too scary and this is the only way that Jacob's original suggestion would work, and I...

quote:

Procedures returning more than one variable:

The returned variable is exactly like defining a variable.

Example:
--------------------------
Window mode 640,480

While not pressed(12)
define()
For i=0 to length
frame oval x-i*2,y-i*2 to x+i*2,y+i*2
Next
Wend

Procedure define()
'Code goes here
End Proc(float x=mouse x, float y=mouse y, float length=100,int i)


This sort of thing is too nasty to contemplate, and in his example he calls define() within a loop! AAARRGHHHH! I'm not even going to think about recursive calls... How big is our stack?

Anyway, felt the need to rant about that, sorry... I feel better now... Honest.

Danny (nods)

02-04-2006 11:24

Posted by:
Wil Hostman

Find more posts by Wil Hostman

Didn't I ask for byref calls 3 years ago?

;)

02-05-2006 16:52

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Yes you did Will, and it's on my old todo list. If you stick it in the feature request tracker on sourceforge then it won't get lost and can be implemented by any free programmer. Go do it now and given the lack of competition in that tracker it might even make the next version of TB. :)

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.