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 Discussion / Function Problem

Author
Message
lockers90
16
Years of Service
User Offline
Joined: 11th Mar 2009
Location:
Posted: 19th Mar 2009 15:33
i am rather new to dark basic and i am trying to create a 3d version of pacman so far without success. at the moment i am having a lot of trouble with a function i have in there. error message ' program ran into a function declaration '. i am unsure how to fix it. my code is bellow if any one has any suggestions then please post.

`**************************
`* Pacman 3D *
`* Adam Lockwood *
`**************************

Dim Mz(30, 30)
Dim VertsX(30, 30)
Dim VertsY(30, 30)
Dim Bump(30,30,1)

Sync On
Hide Mouse
Randomize Timer()

`Clear everything previously
For a = 1 To 29
For b = 1 To 29
mz(a, b) = 0
Next b
Next a

`Make the borders
For a = 0 To 30
Mz(a, 0) = 1
Mz(a, 30) = 1
Mz(0, a) = 1
Mz(30, a) = 1
Next A

`Generate the vertices
For X = 2 To 28 Step 2
For Y = 2 To 28 Step 2
VertsX(X, Y) = X
VertsY(X, Y) = Y
Next Y
Next X

`Mix up the order to draw verticies
For X1 = 2 To 28 Step 2
For Y1 = 2 To 28 Step 2
X2 = (Int(Rnn() * 13) + 1) * 2
Y2 = (Int(Rnn() * 13) + 1) * 2
tmpX = VertsX(X1, Y1)
tmpY = VertsY(X1, Y1)
VertsX(X1, Y1) = VertsX(X2, Y2)
VertsY(X1, Y1) = VertsY(X2, Y2)
VertsX(X2, Y2) = tmpX
VertsY(X2, Y2) = tmpY
Next Y1
Next X1
`Now here is the confusing part. Using a method I found
`on the internet We are simply going to draw
`a wall from each verticies in a random direction
`Until another wall is reached
For X = 2 To 28 Step 2
For Y = 2 To 28 Step 2
XX = VertsX(X, Y)
YY = VertsY(X, Y)
If Mz(XX, YY) = 0
Repeat
Cnt = 0
XX = VertsX(X, Y)
YY = VertsY(X, Y)
Dirn = Int(Rnd(3))
Repeat
Cnt = Cnt + 1
T=0
If Dirn=0 then XX = XX - 1 : T=1
If Dirn=1 then XX = XX + 1 : T=1
If Dirn=2 then YY = YY + 1 : T=1
If T=0 then YY = YY - 1
Until Mz(XX, YY) = 1
Until Cnt < 26
XX = VertsX(X, Y)
YY = VertsY(X, Y)
Repeat
Mz(XX, YY) = 1
T=0
If Dirn=0 then XX = XX - 1 : T=1
If Dirn=1 then XX = XX + 1 : T=1
If Dirn=2 then YY = YY + 1 : T=1
If T=0 then YY = YY - 1
Until Mz(XX, YY) = 1
EndIf
Next Y
Next X

Cls


`Now just display the maze on the screen
For X = 0 To 30
For Y = 0 To 30
If Mz(X, Y) = 1
Make Object Box X+1+Y*31,100,100,100
Position Object X+1+Y*31,X*100,50,Y*100
Endif
Next Y
Next X

Color Backdrop 0


Do
This is the part i am having trouble with
Function Create_Chars(Tex)
`PacMan
rem make object sphere 8,30
load object "obj/pacman.x", 8
make object collision box 8, -14, -14, -14, 14, 14, 14, 1
fix object pivot 8
rem rotate object 8, 0, 180, 0

make object sphere 13,40
if Tex=0
color object 13,rgb(0,0,255)
else
texture object 13, 7
endif
position object 13,-50,-50,-50
ghost object on 13
make object collision box 13,-20, -20, -20, 20, 20, 20, 1
`Ghosts
For i = 9 To 12
rem make object sphere i,60
load object "obj/ghost.x", i
fix object pivot i
remstart
if Tex=0
color object i,rgb(200,200,200)
else
color object i,rgb(200,200,200)
endif
remend
ghost object on i
make object collision box i,-25, -25, -25, 25, 25, 25, 1
Next i
endfunction

to this part here

x#=250
z#=380
a#=0

color backdrop 0


if upkey()=1 then x#=newxvalue(x#,angle#,-2.0) : z#=newzvalue(z#,angle#,-2.0)
if downkey()=1 then x#=newxvalue(x#,angle#,0.3) : z#=newzvalue(z#,angle#,0.3)
if leftkey()=1 then angle#=wrapvalue(angle#-4.5)
if rightkey()=1 then angle#=wrapvalue(angle#+4.5)

position object 99,x#,y#,z#
cx#=newxvalue(x#,wrapvalue(angle#),12)
cz#=newzvalue(z#,wrapvalue(angle#),12)
position camera cx#,y#+10,cz#
point camera x#,y#+5,z#
yrotate object 99,angle#

sync
loop

Function Map()

Ink RGB(255,255,255),0
For X = 0 To 30
For Y = 0 To 30
If Mz(X, Y) = 1
For E=1 to 5
For E1=1 to 5
Dot (X*5)+E,(Y*5)+E1
Next E1
Next E
Endif
Next Y
Next X

Endfunction

Function Rnn()
I#=Rnd(10)/10.0
While I#=0 or I#=1
I#=Rnd(10)/10.0
Endwhile
Endfunction I#
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Mar 2009 20:42 Edited at: 19th Mar 2009 20:44
you declare functions outside and after you loop then if you want to use them you call them by there name and parameters

like this (doesn't return anything)

sync on
synce rate 0



or you can have a return value like this




functions are ussually used for peices of code used alot in your program so then you only type it once and can use itanywhere in the program.

you can return any kind of variable(int,string,float)

hope that helps


oh and you don't want to make your objects in a loop.

because your program would try and make the same object again on the next loop and cause a error

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 20th Mar 2009 03:08
nice caleb, basically if you think of running a program as moving a line from the top of the code towards the bottom, running each code the line touches, the line CANT touch the function declaration (Function Create_Chars(Tex)) or this error occurs
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Mar 2009 05:12
use the search box at the bottom of the page to search for "program structure" you should get my tutorial that is all about this sort of thing, should be helpful.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Mar 2009 07:13
smartguy:

thanks. and yup exactly!

Obese:

I love it when people arn't lazy like me and right tutorials

New Site! Check it out \/
lockers90
16
Years of Service
User Offline
Joined: 11th Mar 2009
Location:
Posted: 20th Mar 2009 15:59
WOW thanks guy all this help is much appreciated

TY

Login to post a reply

Server time is: 2025-05-17 00:37:47
Your offset time is: 2025-05-17 00:37:47