Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / _sun routine\'s passing Varibles

Author
Message
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 2nd May 2005 23:42
Afternoon all.

I have created a subrouting which I would like to pass somelocal varibles to. Can this been done? I\\\'m a fan of local varibles so if this can be done then great.

Look forward to hearign from all you better programmers than me...

Cheers

Colin.
TEH_CODERER
20
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 3rd May 2005 00:21
Isn't the idea of local variables that they can't be used in other parts of the program? I think you are going to have to use global variables.

[url]andrewneale2004@yahoo.com[/url]
http://www.elbsoftware.tk
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 3rd May 2005 00:44
Are yes that is correct... however passing Local VAR's to another routing using local VAR's

Its cheating in away.. yes they could be global, but it gets a bit heavy at the top. using locals keeps things neat and tidy.

Also the question of performance? Do all varible get declaired on execution? or are they declaired whenthe routin is called?

Colin.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd May 2005 01:26
Sorry if ive really missed the point here but wouldnt you just use a function for that?

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 3rd May 2005 01:34
If you are just using Goto or Gosub, then local variables will pass automatically. If you use a function, then local variables don't pass to the function unless you pass them in the function declaration (i.e Function MyFunc(ObjID,x#,y#,z#)).

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 3rd May 2005 01:55
As RiiDii said...if you use a gosub...(or goto) then local variables are passed automatically...

like so...

As you can see they are the same...

--Peter

"We make the worst games in the universe."

NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 3rd May 2005 07:28
Colin Hart,

If I understand you correctly, you need to pass a local variable's values to a function which lies within a seperate file. Almost, as to say, you need to pass the variable's values to a function which is held in a 'library' somewhere. If so, I have two code snippets below. The first is the main file, or in other words, the driver file, and the second is a function holding type library. Save them as two seperate .dba files, and make sure that the second snippet is saved under the name functions.dba. Also, make sure that they are both saved in the same folder.

[1.]


[2.]


Notice, the include file command within the first file. It is how you include functions from other .dba files.


+NanoBrain+
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd May 2005 08:16
Whether the function is in an include file or not isn't important, it will work either way.

Functions use local variables, Subs do not. In DarkBasic, there are several exceptions to this rule, see the tutorial linked further down.

Functions create their variables when they are called. The reason is simple...You may have the same function in your call stack several times, and each one will have it's own set of variables.

If you want to know more about functions and how they work, take a look at the March Tutorial...

http://www.thegamecreators.com/data/newsletter/newsletter_issue_27.html

BatVink

Login to post a reply

Server time is: 2024-09-23 19:28:45
Your offset time is: 2024-09-23 19:28:45