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.

2D All the way! / problem with If coding

Author
Message
It_wasnt_me
10
Years of Service
User Offline
Joined: 3rd Jul 2013
Location:
Posted: 3rd Jul 2013 06:51
I'm just learning DarkBasic and I'm having a problem with a section of coding regarding If statements.
if check$=puzzle$ then goto win:
if tec<1 then blg=blg+1 else goto rodentclick:

if blg=1 then box 114,346,133,362, rgb(255,0,0), rgb(255,0,0), rgb(255,0,0), rgb(255,0,0):goto rodentclick:
if blg=2 then box 136,346,155,362, rgb(255,0,0), rgb(255,0,0), rgb(255,0,0), rgb(255,0,0):goto rodentclick:
if blg=3 then box 158,346,177,362, rgb(255,0,0), rgb(255,0,0), rgb(255,0,0), rgb(255,0,0):goto rodentclick:
if blg>3 then goto lose:
goto rodentclick:

win:

for some reason when running the program, it draws each of the boxes and ending up at the lose: label rather than allowing for the three wrong guesses. Any suggestions?
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 8th Jul 2013 09:56 Edited at: 8th Jul 2013 09:57
Learn how to write a Select & Case commands.



I'd also recommend not using GOTO commands. They'll lead you to no end of trouble and are extremely bad practice.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Jul 2013 22:37 Edited at: 8th Jul 2013 22:48
You can put code into code snippets using the code tags:
{code}code goes here{/code} (Use square brackets instead of curly)
Code snippets are neater and also preserve your indentation -- you are indenting your code aren't you?

The colon has two behaviours, it acts as both a line delimiter and a label definer. Using it as a line delimiter allows you to put more than one command on the same line, I see you are already using it for this purpose. With regards to labels, you only need to use a colon when defining a label; omit the colon when calling it.
eg if check$=puzzle$ then goto win

You need to get out of the habit of relying on GOTO, there are far better ways to control program flow.

This isn't really the right board for this. You should head over to the DBP Newcomers board and ask for help there.
It_wasnt_me
10
Years of Service
User Offline
Joined: 3rd Jul 2013
Location:
Posted: 17th Jul 2013 06:27
Thanks for the info guys, but the select/case gives me the same problem I've been having with the IF statements. Here is the prgram thus far:


Also, when I use the DIM statement, the program crashes on exit:
Problem signature:
Problem Event Name: APPCRASH
Application Name: hangman.exe
Application Version: 1.0.0.0
Application Timestamp: 415d6c05
Fault Module Name: dbprocore.dll
Fault Module Version: 1.0.0.0
Fault Module Timestamp: 4c17df96
Exception Code: c0000005
Exception Offset: 00003e44
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Additional Information 1: 34dc
Additional Information 2: 34dcca08ee00438866b0857992f40c04
Additional Information 3: 3ef3
Additional Information 4: 3ef398eac2d7422496ce882bb8c948ad
Any ideas why setting an array would cause the program to crash? When I remove the REM statements from the lines to set/check values, it crashes before running...

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-02 07:55:49
Your offset time is: 2024-03-02 07:55:49