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.

DarkBASIC Professional Discussion / problem with gosubs and possibly UDTs

Author
Message
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 2nd Oct 2011 18:38
ok i have this problem

i have some hundred lines of code where i would like to move the part that comes before the main loop into a subroutine.

the setup part contains definitions for the user defined variables and it defines some variables as those.

now when my code looks like this:

gosub _setup:

do
do something with the defined variables
loop

_setup:
define them
return

it reports an error that says that the variables that should have been defined are not defined. ( variable p does not exist )

it works perfectly fine when i do it without the gosub
i have many other working subroutines inside the loop

I have quad checked for spelling mistakes int the gosub and put stuff like wait key into them but it doesnt even seem to enter the sub routines!

here is a piece of code that reports the error for me
sync rate 60
gosub _setup:

do

dot p.x,p.y
sync : cls
LOOP

_setup:
type UDT
x as integer
y as integer
endtype
x = 500
y =200
return
[/code]

help appreciated[code]Rem Project: Dark Basic Pro Project
Rem Created: Sunday, October 02, 2011

Rem ***** Main Source File *****
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 2nd Oct 2011 18:43 Edited at: 2nd Oct 2011 18:46
Like this ?
Stab in the Dark software
Valued Member
23
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 2nd Oct 2011 19:38
noobnerd,
You can declare UDT’s any where in your files, even in a separate file. UDT’s are set at compile time so they do not have to come before the Do/Loop. There is one exception when declaring a UDT that uses another UDT. They need to be in order.

[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 2nd Oct 2011 20:34 Edited at: 2nd Oct 2011 20:34
@ empty yes, like that

@ stab in the...

thats not what i am doing :/
didnt even know it was possible thanks

Login to post a reply

Server time is: 2026-07-10 20:11:51
Your offset time is: 2026-07-10 20:11:51