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 / [DBP]Working Code to Function Help

Author
Message
Reynard
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: CT, USA
Posted: 7th Feb 2007 05:27
I am having trouble inserting code that I tested in a "stand alone" program" into another file as a function. The intent is to create a particle explosion for blowing up asteroids. In the stand alone test program, it worked. Here's the code:



But, if I try and build it into the other prgram (as 2 functions, in this case) I get an error. Here's the code where the functions are called:



and the function code:



NOTE: some object numbers differ between the stand alone code and the program/function code simply by virtue of the former existing only to see if I could make a particle explosion.

Unfortunately, I have been fiddling with this for a while now, so neither of he coe sets exist in their original state and, as I have changed things, the errors have ranged from the particle appearing but not flying to getting an "object already exists" error (I already ran through the whole program code to make sure I wasn't calling or creating an object that I had made previously).

I am pretty sure that I am just missing something -- not even so much about functions, but about levels of if..endif statements and/or for..next loops.

Thanks a ton.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Feb 2007 10:43
The most common cause of problems encountered with functions containing code which previously worked fine not in a function is down to local variables.

In a stand-alone program, you are probably using Gosubs to procedures which can see all the variables.

When inside a function, all variables outside the function cannot be seen unless they are declared as global.

Worth checking...

TDK_Man

Login to post a reply

Server time is: 2024-11-26 00:27:05
Your offset time is: 2024-11-26 00:27:05