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 / Help, Last line of my program is always wrong... what did i do???

Author
Message
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 06:53
My program has no errors other than that no matter what i do, the last line is always wrong so i cannot actually run it or test it. What can i do to fix this?
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 11th Dec 2010 11:46 Edited at: 11th Dec 2010 13:34
Lets start with the good stuff...
I admire your willingness to learn programming and being creative
with DarkBasic Pro!
It can be lots of fun, and frustrating at times too.

Now for the not so good stuff...
You should learn to NEVER use goto's in your programming code,
they make for bad coding habits.

So now that you are not going to use goto statements any more,
we can help.

Start by learning good programming style
1) indent your code
2) no goto's....ever....or only 1 every month, or year maybe.
3) save your program often with revision numbers
like: myprogram-1, then myprogram-2, etc. at least every day that you work on it, sometimes many times in a day.
Saving after each hour of work is a good place to start.

There are other things to learn also, but starting with these is a great first step.

If you had indented your code properly, you would have noticed too many unclosed if statements.
Every IF statement that is all on one line needs a THEN statement
Every IF that uses multiple lines needs an ENDIF statement
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 11th Dec 2010 13:32 Edited at: 11th Dec 2010 13:33
I have fixed your program so it will compile (it did have dozens of errors),
but it doesn't work the right way yet, there are logic problems with your code, I had to guess at some of your code ideas.

I hesitate posting your working code here it really is a mess.
It would be best for you to start over with no GOTO statements really.

I am really not trying to be rude here..
In fact I challenge you to rewrite your program with no GOTO's.
If you do, I will help you get a finished program you can be proud of,
just post your new code here and I will help you as you go along.
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 14:10
Ya, i am still working on completely understanding DB and DB Pro
Thank you for helping me, and thanks for the info on not using goto's
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 11th Dec 2010 14:14 Edited at: 11th Dec 2010 14:27
If you would like me to get you started, I will be happy to do so
just let me know.

Good Luck!

In fact, here's some code to get you started...
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 14:22
I am not sure i totally understand what to use to enter seperate outcomes besides goto and gosub...
an i able to have multiple things happen for 1 if?

also, if you are not sure what im doing with this program(completely understandable because i kinda type/write in my own language with my abbreviations...) it is to create a program where someone can enter their name and a number and others can guess it.
-Thanks for the offer to help!
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 14:32
Oh ok, Thanks for the start. Sry about slow responses, havent been un 'noobed' yet, lol
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Dec 2010 16:11
Only glanced at the code, I agree, goto's are not the best for anything more than hello world . Gosub is superior by far, and functions are a newer method. Changing from goto to gosub is pretty easy. As long as you make sure you return back to the gosub you will have no problems. You can nest gosubs but remember to make sure your program is designed to allow them to return all the way to your original gosub. Or just use functions.
For instance a typical basic game loop for me would normally start like this and expand from there.

That is the basic structure I use a fair bit myself, as I am old school and find gosubs a doddle, and functions in general to be unnecessary. I rarely define global or local variables preferring to stick with global as standard. Obviously, you add gosubs like functions and work from there. Either way is fairly easy, I just find I prefer gosubs to functions in the main, other peeps will work the other way round

http://s6.bitefight.org/c.php?uid=103081
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 18:06
Thanks for all the help guys!
i am going to attempt to use some gosubs and alter the methods of getting names and guesses to make them much more simple.
i will post my new version when it is done, though that might be a while from now...(homework is horrible)
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 11th Dec 2010 23:28
ok, this is the new program with proper indentations(i think...)
also no gotos. it has gosubs, but im not sure how well i made it. any suggestions are appreciated, plus, i cant think of how to make the program recognize who is closest to the number.
Thanks!
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Dec 2010 01:12
You did something wrong with your attachment.

It looks like all it attached was the project file (stores info about the projects and some settings, points to source files, but doesn't include the actual source code)

You should just zip your project folder and upload that zip, so it includes all your files in the project directory

Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 12th Dec 2010 04:20
erg...
wow im just screwing up alot today!
ill try it again
lemme know if i screw this up too lol.
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 12th Dec 2010 04:26
er...
disregard this one. im trying to figure out how you ppl post code snippets in that thingy link deal...
ya like i said, disregard this probly.

if it worked heres the code for the program...
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 12th Dec 2010 05:00

ok, i edited it but now its looping where i dont want it too. now im completely lost on what im doing wrong...
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 12th Dec 2010 12:51
Hi Veero Rith,

I noticed you were using sync (on), but I don't think you will need it in this program. It seems to be working so I guess it doesn't matter that much.

The problem is most likely in this part:


Due to the nested conditions, you'll never detect if the player has selected anything but 1. If you try to input 2, it will skip the whole code in the code snippet! I think that what you're trying to achieve is this:



This code is a schoolbook example of where you can use a select-endselect block, like this:


This will give the exact same result, but is faster (it is compiled a little differently).

Cheers!
Sven B

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Dec 2010 13:03
Well, I noticed one thing straightaway without delving into your code. Your first gosub, i.e.



points to code INSIDE the main do loop. The gosub code must be outside the do/loop block just like the others are outside their if/endif blocks. In fact why have you got that first do loop at all - it just repeats the first gosub indefinitely? Perhaps that was intentional?

Your code is much easier to read now so you are making good progress. Two further suggestions though:

1. indent the code inside the do/loop pair and gosub code as well - makes it much easier to see the start and ends of the loop and subroutines
2. use select/endselect and case/endcase instead of all your if statements

These are just optional - but might help your code look neater and easier to read.

You can use select/endselect as follows:

Instead of



you could use



(I've used spaces to indent - but you can change those to tabs if you prefer.)
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 12th Dec 2010 16:42
ok, ill work more on that.
thanks!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2010 17:53 Edited at: 12th Dec 2010 17:56
You can greatly reduce code using arrays and FOR/NEXT loops to do things that repeat. The following code works for as many people as you want guessing even if it's a million people.



If you haven't already you should check out TDKs Tutorials to learn the basics of Darkbasic.

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

It's nice to see the GOTO cleanup too.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Dec 2010 18:16
Quote: "The following code works for as many people as you want guessing even if it's a million people."


Yes, that would be better still. But one step at a time.
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 13th Dec 2010 21:15 Edited at: 13th Dec 2010 21:22
Thing to remember with gosubs is always be neat and tidy. Always make sure your gosub label has a clear return point, which will always be followed even if you gosub out of the loop you gosubed into. lol. Sounds complicated even to me and I'm trying to be simple.
For example the start of your code as people have mentioned.

Do
gosub Names

Names:

You have a label within your do loop. That is nearly always going to fail. Always contain your gosubs within a loop, unless you are just loading a setup or such at the start.
Here is your code working, I think...

You were checking at the end for a string input and checking for a numerical one. Which was the last piece of the puzzle so to speak. Don't use if statements nested like you did unless you are checking things that can be checked through each statement, or to block certain things from happening. When it returns at the end, if you want to reset data then reset any variables or arrays you have, before the return command.

http://s6.bitefight.org/c.php?uid=103081
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 14th Dec 2010 02:21


ok, i think this is good, but i cant figur out the logic, and how the program can decide who is closest and include all ppl but not too many... i need sum halp plz
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 14th Dec 2010 02:22
ill work on it in the meantime.
erg hard to think w/ my crazy older brother...
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 14th Dec 2010 02:50
also how do i restrict numbers to 1-10 only without having to go to a subroutine and ask if they want to try again at start. can u state restrictions previously?
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 14th Dec 2010 14:58
This will give you the difference between the guess and the actual number.


Then you can tell if a player guessed higher (a negative value) or lower(positive value), and the difference between guess and the num, being 0 if you hit it spot on. You should be able to work this into your code.

http://s6.bitefight.org/c.php?uid=103081
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 16th Dec 2010 00:45

This is my almost completely working program .
its only error so far is that it thinks everyone won and guessed the right number, but im not sure why.
any 1 know why?
(btw, all the stuff for that is in the numbig, numsmall, correctnum, and players_and_guesses sections of code. as far as i know at least.)
thanks all!
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 16th Dec 2010 02:20 Edited at: 16th Dec 2010 03:20
when you want to figure out the guessdist, the variable you want
to store the number in always goes on the left of the = sign.

also, your numpickr variable should be a string variable numpickr$

Your program has come a long way since you started
Nicely Done!

I think a results page with all the stats shown at once would be better for the players to see, showing all the results at once.

Even better would be showing distance for all players


Keep up the good work!
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 17th Dec 2010 01:33
Thanks!
Veero Rith
15
Years of Service
User Offline
Joined: 10th Dec 2010
Location: Idaho, United States
Posted: 17th Dec 2010 23:17
It Is FINISHED... until i decide to make it cooler...
check it out!

Login to post a reply

Server time is: 2026-07-21 07:03:30
Your offset time is: 2026-07-21 07:03:30