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 / Need some help with a code problem please

Author
Message
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Mar 2013 15:31
I am sure there are better ways to write this code so any advice on streamlining it or writing it better will be appreciated. This really will not be a game I am just trying to learn how to write these routines and get them working. There will be about 10 bldgs that will work with all the functions I want to create such as a bank, shop ect... This will be text based and once I get this running and working right I will start working on making it 2D, sprite based and then on to 3D.

Anyway I have a do loop at the top calling a screen setup function then a bunch of functions. Most are stubs, the screen setup function is coded and the adventurers function has code. I know what my problem is I just don't know how to solve it.

If you run the code you will see how it works and the menu choices. If you type the choices the program will show the function name on the left, even choice 1 if I put the function name in the stub. I have put cls in there and it does not work, WHY because I have screen setup being called from the do loop.

I have tried different loops and get the same results. I have tried doing away with the do loop and just putting the screen setup stuff up and then calling the adventure guild menu and I get an error saying I have hit a function deceleration in mid program.

I am sure this is pretty basic to a lot of you but I am missing something and when I get it I will probably have one of those how stupid am I moments.

So thanks in advance!!! Here is the code for you to check out.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Mar 2013 16:39
I forgot this, what I want this program to do is every time a choice is made I want the screen to switch. I want the basic layout to stay the same but on the right I want new options to come up for the choice made.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 13th Mar 2013 19:20
Hi, some suggestions I have for you:
1. Create an image that would serve as a template instead of drawing lines manually every loop. Use MS paint if nothing else is available. Then you can just paste the image when needed.
2. Structure it a little differently. Instead of having a main loop that endlessly goes to one function, create one that will enable the program to flow in such a way that you will be able to follow what is happening more easily. Main loops can have player input / movement, Enemy movement, collision checking (not needed for text, but will be needed for 2D and 3D), updating the heads up display (HUD) and any debug info you need to show. So, instead of calling one function, you might be calling 4 or more.
3. I don't know if you understand GLOBAL variables or not; if you do, what you have is fine. If you don't, you might consider using GOSUB to a subroutine instead of using functions.
4. I would assign a variable to help you know which screen you are at, say CurrentScreen for example. If CurrentScreen = 1 then you jump to the AdventurersGuildMenu() function; if CurrentScreen = 2, then you jump to the AddMember() function and so on and so forth. It is a way to control the flow of the program. If using functions, CurrentScreen would need to be declared as global.
5. To get rid of hitting a function declaration error, put an END statement after your main loop.
6. As to what to do after a choice is made, you simply jump to the function / subroutine for that task, print out the info needed and check to see if the user has provided acceptable input.
7. To clear an area of the screen set the ink color and draw a box in that area.

Hope this is helpful.

So many games to code.....so little time.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Mar 2013 21:14
Ok I have not done any image stuff with DBP yet as I have been trying to do strictly text right now but I do understand what you are saying there and I do know the commands and I have gimp so not a big deal to do this but since I am trying to learn things I was thinking of setting my screen setup stuff in a udt and use array's to print a screen.

I do know about Global, GOSUB and subroutines but I would like to use functions.

So If I understand you right I could do away with the main loop for now and also the case statements and use variables to move from screen to screen and function to function?

Then when I get these functions and this little program working right I want to use mouse commands to make options clickable and that kind of thing goes into a main loop, (DO-LOOP) right?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 13th Mar 2013 21:29
No, I wouldn't do away with the main loop, I would reorganize it. Something like this:


In your DrawScreen function, you check to see the value of CurrentScreen, and you draw lines, place images, print text, etc. for that particular screen.

For the UserInput function, you also base the input upon which screen you are on. The options are likely to be different if the user is at the AddMember screen versus the CreateCharacter screen. This is a little different than what you have done, but I think if you think it out, you can organize it to work efficiently.

I personally prefer to use REPEAT - UNTIL loops instead of DO-LOOPS, but really it is up to you.

So many games to code.....so little time.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 14th Mar 2013 00:00
Ok I understand THANKS!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 16th Mar 2013 01:08 Edited at: 16th Mar 2013 01:09
The accepted practice in controlling your game is to use "Game States".
Here is a suggestion for "Game states", check out this post.

http://forum.thegamecreators.com/?m=forum_view&t=188108&b=1

I posted a code example there download it and try it, if you have any questions Just let me know.
Also always use a "DO LOOP" for your main loop it is the one that is optimized for rendering in DBPro.
Subroutines are a poor coding practice. Stick with functions.

[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.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 16th Mar 2013 22:22
I downloaded it and had a quick look. Unfortunately I am not that experienced in coding. I have hands on vol. 1 book but just can't get into following it chapter by chapter. I use it as a reference to do things like I posted in this thread. I enjoy learning to code but it is extremely frustrating to me also. It seems like I run into problems every time I turn around and can't quite figure out how to learn in a fun way.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 16th Mar 2013 22:53
SITDS:
Honestly, you really expected him to learn from that? He's posting in the Newcomers Forum, for crying out loud. It almost looks like a shameless plug for your IDE. You are correct, however, in that using game states is an accepted practice, but your example is way too complicated for someone posting here.

I don't know where you get that subroutines are poor coding practice, because I have not heard others stating such. I have heard others (rightly, I think) suggest to newer coders to use subroutines until they become a little more well-versed at coding, as functions require more understanding to use properly. Since Dragon Slayer showed no global variables in his posted code, it seemed to me that he was not quite ready for functions and would possibly get frustrated.

Dragon Slayer:
Coding can indeed be a fun and rewarding hobby and if you're good enough, perhaps even make you a few bucks along the way. However, there will likely be many times frustration will set in when you can't seem to get something working right. I have found that when I search diligently here on the forum, or work to understand tutorials most all of the time I can find some help for what I am trying to do. It is a learning process that takes time.

So many games to code.....so little time.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 16th Mar 2013 23:24
Well one thing I am thinking of doing is going through the book page by page, chapter by chapter and learning from the beginning. That can get boring but I am getting nowhere fast doing what I am doing. It may take a long time and get boring but I guess I will get a good solid base.

I know in my head I know what I want this little program to do. As I work through the book and do the projects in the chapters I am sure I will be able to work on this program too!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 17th Mar 2013 02:11
LBFN,
Yes, I expect him to learn from the example. Before you jump to conclusions take a look at his profile.
I did that's why I decided to suggest that example. His previous posts seem to suggest he already knows; arrays, functions,
function pointers, global and local variables.
Yes it is a shameless plug; the banner is there to help people.
We created a better IDE to help ourselves with coding if it can help somebody else why not.
We have been on these forums a long time and have learnt a lot from other peoples suggestions.
We are only trying to pass on that knowledge.
Subroutines are bad coding practice do some research. They lead to unorganized code that can be impossible to debug.

Dragon slayer,
You will never learn programming by just taking one look at an example and getting the mindset that it is over your head.
I am still looking at code that seems beyond my comprehension but the longer I look the clearer it becomes.
Looking at your profile your asking questions about C++,C#, and DBPro. This tells me you want to know and that is the key to becoming
a programmer.
Turn your frustration into enthusiasm. A good mechanic will bust his knuckles fixing a car but still go on to fix the next one.


[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.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 17th Mar 2013 04:46
Yes I am all over the place and have done some studying on all of those languages and can do a little in each but C++ and DBP I know a little better than c#

I do know about arrays, functions,function pointers, global and local variables. I am not really skilled at any of it and I don't really get pointers.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 17th Mar 2013 15:12
OK I have cut this code down some. I will try it one function at a time. Get my create character code working once I solve the problem I have with the code I have. I am missing something probably very simple. Here is my code



So here is the problem. At the very top of my code I have some set up. I want the screen to always have this. I can call the first function which puts the menu option on screen. If I hit 1 the program just exits. I want to hit 1 and have the program bring up the create character options on the right side and then go from there. Do I have to hard code all that setup stuff into every function? Is there something I can do with this code in a udt and array? I have to check up on that can I use a udt array in a function? I could put my setup in a udt and array and run it in every function. Don't even know if that would be right, just throwing things out there now!

I know about a lot of this stuff but I don't think I am formatting the code right, putting things in the right place. I have tried putting the the code in different loops and it still wont work right.

For now all I want is for the screen to have this basic setup. Menu options on the right, if I hit 1 I want the menu options for that option replace whatever is in that box on the right.

I hope I made this understandable. I have to go pick up my semi truck now and will work on this more when I get back.

Thanks
Dragonslayer
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 17th Mar 2013 16:27
Here you go the problem was the "input" command. I've never used that command might be a bug I will investigate.



Very interesting a DRIVER, I drove for TRL and CONWAY and I lived in Rantoul once upon a time.
If you can shift gears, read a map, talk on the CB, and eat lunch all at the same time programming is easy.

[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.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 17th Mar 2013 18:11
Ok I will look into this! I know who TRL is. I live just north of Kankakee. I am an owner operator. I haul steel out of the mills in the Gary In. area. I run a lot to Granite city. It pays good, pays the same to go back up also and it gets me home every night if it works out right. Things are very slow out of Granite City now. I am going there tomorrow. I am leased on to Great American Lines.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 17th Mar 2013 18:38
So I did not do a set display mode in my code I set it in my editor but probably better to hard code it. I really don't get the need for the sync command or the backdrop command since this will be text only for now. Really don't understand the rotating cube. Know how to make it but don't see the need for it here. I will go play around and come back later!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 18th Mar 2013 00:10
I understand you're just making a text program, but I thought I would show you the basic setup for DBPro.
What you can do with console text commands is limited.
Setting the display mode can be done in the editor but it is deprecated.
One of the most important coding practices in DBpro is that you need to control your display modes.
If you pick a display mode in the editor that the user's graphics card can't handle it will crash.
If you do not call "sync on" and call "sync" in the loop DBpro automatically syncs (refreshes the screen)
at every line of code in the loop. Calling "sync" will refresh once every loop. Also the "set display mode"
command's parameter for Vsync, sets the sync rate to match your monitors refresh rate.
This will keep the frames per second of your program to 60 fps.
Creating the cube was just an example of 3d rendering.

[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.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 18th Mar 2013 01:31
Ok I got it, it worked good. Just wish I could catch on to it better. I get fed up too quick! It just does not happen fast enough for me.

Login to post a reply

Server time is: 2024-11-23 14:57:23
Your offset time is: 2024-11-23 14:57:23