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 / Can solve the errors!!

Author
Message
The horror expert
18
Years of Service
User Offline
Joined: 30th Aug 2006
Location: hidding in my closet!
Posted: 12th Apr 2007 20:42
I can't test my game as i can run because of two errors i don't know how to solve.

1) Function declaration `Button` must be outside any program nest at line 291

2) Could not close nest at line 744

just ask if you need to know more of the code in order to help

Check the closet an extra time, i might be in there!
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 12th Apr 2007 20:45
Sounds like you didn't close an if block, but more code would be helpful.

Who needs a signature?
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 12th Apr 2007 21:01
Right, it does sound like you forgot to close an ifblock or a for nest somewhere. If you didn't, make sure you aren't trying to declare a function within a nest (if or for etc.) of any kind.

Terrain Generation has a whole new face.
The horror expert
18
Years of Service
User Offline
Joined: 30th Aug 2006
Location: hidding in my closet!
Posted: 14th Apr 2007 15:26 Edited at: 14th Apr 2007 15:26
This is my code; its the function i got problems with!


Do
If Button(20,55,"New Game")=1 then Goto New_Game
If Button(20,95,"Continue")=1 then goto Continue
If Button(20,135,"Option")=1 then goto Option
If button(20,175,"Credits")=1 then goto credits
If button(20,215,"Quit")=1 then goto Quit

loop

New_Game:
Cls

Continue:
CLs

Option:
CLs

Credits:
Cls

Quit:
cls
Set cursor 520,350

Do
If Button(500,350,"Yes")=1 then Goto Yes
If Button(560,350,"No")=1 then goto No

loop

Yes:
End

No:
goto mainmenu

function Button(x1,y1,WORDS$)
Pressed=0
x2=Text Width(WORDS$)
y2=Text Height(WORDS$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
Pressed=1
endif
endif
if pressed=1 then ink rgb(255,0,0),0 else ink rgb(255,255,255),0
if pressed=1
Pressed=Mouseclick()
else
pressed = 0
endif
text x1,y1,WORDS$
endfunction pressed


Check the closet an extra time, i might be in there!
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 14th Apr 2007 15:37 Edited at: 14th Apr 2007 15:38
The only obvious problem there is:

goto mainmenu

the label mainmenu doesn't exist... It probably does exist, but it's not here. Other than that, nothing obvious, the error is likely to be somewhere else in your code
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Apr 2007 15:57
@ horror expert
I copied your code and other than the 'mainmenu' label being missing, it worked fine. The errors must be elsewhere in your code.

The use of GOTO is not recommended. Based on the code shown, you are jumping to locations and then the program is not directed to go anywhere else and it simply falls through to whatever comes next. For example, when you goto New_Game, the program clears the screen and then falls through to Continue.

You should use GOSUB instead of GOTO and then return from the various subroutines. The function itself is working fine.

LB
The horror expert
18
Years of Service
User Offline
Joined: 30th Aug 2006
Location: hidding in my closet!
Posted: 14th Apr 2007 16:19
I tried that, but it still dosn't seem to work!
It still display the error:

Function declaration `Button` must be outside any program nest at line 313

I got plenty of other `Buttons` connected to that function, could the error lie there??

Check the closet an extra time, i might be in there!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Apr 2007 16:46
@ horror expert

Using GOSUB instead of GOTO was not intended to fix the problem, it was just some programming advice.

I don't see where we can be of much help without seeing your code. If you decide to post it, copy the text, click the CODE button, move the cursor to after the word [CODE], paste your text and then click the [CODE] button again. This will put all of the code into a snippet.

LB
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2007 18:45
Quote: "If you decide to post it, copy the text, click the CODE button, move the cursor to after the word [CODE], paste your text and then click the [CODE] button again. This will put all of the code into a snippet."


And... also indent your code! It makes it lots easier for experienced programmers to read - and therefore understand.

This will greatly improve your chances of someone helping you.

If your code is quite long and indenting would take too long, download DBATidy from here:

http://forum.thegamecreators.com/?m=forum_view&t=104136&b=7&p=0#m1167942

TDK_Man

Login to post a reply

Server time is: 2024-11-25 20:31:37
Your offset time is: 2024-11-25 20:31:37