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 / User defined functions, reference variables

Author
Message
Novaguy
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 2nd Apr 2009 22:43
I'm relatively new to DarkBasic Professional, but I do have a bit of experience in C++, so learning this language is pretty easy. One thing I'm having trouble with, however, is making a user defined function that can use reference variables instead of local variables.

Here's the C++ version of what I'm trying to do (It's a little sloppy and may contain some sytanx errors since I've been focusing more on DBPro lately, but here's the gist of it):


Here's what I have in DBPro


Basically, I'm going to position bullets to the end of a gun and have them come out like that. They used to work without the user defined function, but for the sake of practice and organization, I'm trying to cut down my code a bit and make a function that will set these 3 variables. When I tried the user defined function, it seemed to stop working properly. It's possible I accidentally changed something else, but I'm relatively sure this is the problem.

Is there any way to make this user defined function work in DBPro?
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Apr 2009 23:27
As far as I know you cannot do that in DBP.
For larger amounts of data you can store it in a memblock and pass the function a pointer to that (which you can retrieve), but as for regular values, you have no other choice than to declare them as globals for such use, I'm afraid.

Novaguy
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 2nd Apr 2009 23:30
how do you set global variables?
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 4th Apr 2009 16:21
You can either set them in an array, a UDT, or declare them with the GLOBAL command.

Also, in you're function I think you have it wrong. Oh, wait, never mind! I see what you were trying to do.

Anyways, you might just be able to use a for-next loop if you're trying to do a large quantity of objects. i.e.



Is that what you're trying to do?

That's what they WANT you to think...
Novaguy
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 5th Apr 2009 02:03
Yeah, sort of. I found a lot of times when I was setting three variables to object coordinates, so I ended up making an array of pos#(x), pos#(y), and pos#(z). The array is global. The function looks like this:

So now when I need to position objects like bullets to a gun, I can do this:

But yeah my question was answered. I needed to learn about global variables and global arrays. Thank you both for your help.

Login to post a reply

Server time is: 2024-11-24 09:19:46
Your offset time is: 2024-11-24 09:19:46