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 / Text Adventure Bug

Author
Message
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 14th Nov 2013 08:29
Greetings!

So I have been creating a text adventure and run into a few snags...
The first one is killing me
What the bug is, is that when the text gets to the bottom of the screen it will replace the second last line displayed with...

"You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT"

whenever you make a choice. I was thinking maybe creating a box that is scrollable a having the text in that but I have no idea how to do that.

I have linked the full source code of my project below.

The second issue I have is my item system. I'm not 100% sure how to make the program save 10 gold picked up though objects. I'm assuming it's to do with the array...



I am using the CodeSurge 1.4c IDE if that makes a difference.
I tried putting it into the original DarkBasic compiler but alas, the same bug.

The screen resolution should be 1600x1200x16 fullscreen.

I really appreciate any assistance.


DividedV -- YouTube Channel
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Nov 2013 00:22 Edited at: 15th Nov 2013 00:28
I ran you code using the default editor and didn't see the problem you described and couldn't see any reason why the line "You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT" should be displayed more than once. The line was printed once at the start and then scrolled off the top of the screen as the game progressed so I can't help there.

In terms of saving the amount of gold the player has, replace this:



With something like:



Or you could use the INC command, it doesn't really matter. If you do this each time the player picks up gold (in the form of items) the amount of gold they have will increase.

As for the layout and the "scrolling text box". Using INPUT and PRINT is always going to be a little simplistic and it might be worth looking at the TEXT command and then maybe having a different way of inputting the actions. For instance, it would be fairly easy with your code to replace typing in the action with simply pressing a number key corresponding to the choices available, ie:

"The village is small and has a path to your FRONT [1], a temple to your LEFT [2] and a blacksmith to your RIGHT [3] or you could go BACK [4]."

You could then just scan for a single button push using the KEYSTATE or INKEY command instead of INPUT and this will make it easier to lay everything out using the TEXT command.

I personally didn't mind the text disappearing off the top, although losing the character sheet is a bit of a pain. However, the way your doing things at the moment, it'd be quite a major modification to your code to get this working.

one of these days I'll come up with a better signature
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 15th Nov 2013 00:43
Quote: "
I ran you code using the default editor and didn't see the problem you described and couldn't see any reason why the line "You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT" should be displayed more than once. The line was printed once at the start and then scrolled off the top of the screen as the game progressed so I can't help there.
"


That's okay, only seems to happen in full screen.

As for the gold looting system, your fix worked great! Thanks.

Quote: "
... it'd be quite a major modification to your code to get this working.
"


Yeah I understand that, I guess I won't bother with that at the moment.

Thanks for all your help

DividedV -- YouTube Channel
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Nov 2013 17:14
Sync off : Sync Rate 60 : Color Backdrop 0 : HIDE MOUSE
Sync is off by default. I'm pretty sure sync rate has no effect if sync is off. Color backdrop activates and colours the 3D backdrop, obviously you don't want that for a text adventure. Hide mouse is best put right at the start, if you turn sync on, which would be a good idea, and then hide the mouse it wont hide until the next sync update.

in$ = left$(lower$(trim$(in$)),1)
I had to insert this line, I don't know when you wrote this but you didn't have any of this string manipulation that Kevin Picone and I recommended you do. See how by cutting the string down as simple as possible we make it a lot easier to read the input:
I indented this section as it's not clear what it is doing. This is the problem with GOTO, there's no indication of what is going on and no way to anticipate when a jump will happen, so I tried to make it clearer until we find a better solution. I also changed your error message as shouting "ERROR!!" isn't much help to the player. Making this section into a subroutine makes a little more sense so I've done that.

Print " " : Print "You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT."
You can start a string with a space:
Print " You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT."

PLAY MUSIC 1
LOOP MUSIC 1

Loop music plays the music, you don't need both these commands. This makes me think you are not reading the help files on the commands you use.

Text adventures traditionally use NORTH, EAST, SOUTH and WEST for orientation. FRONT (you mean FORWARD?), LEFT, RIGHT don't make a lot of sense if you think about it, what happens if you turn around!

GOTO Section1
Okay, maybe I've given you a bad habit here. I used GOTO in the input because it was a simple solution and the label was so close to the GOTO call that it was fairly easy to see what it was for. However, when I read this right at the end of the program I think, "where the hell is Section1?", this is obviously bad for following your code and maintaining it.

Hopping from section to section seems logical (I did the same thing making my first text adventure) but it's bad coding, you may as well be writing it out on paper if you're going to do it like that. A better solution is to create a routine for handling sections and then read the data for each section into it, this means far less code and no confusing jumps, also it's much easier to add new sections to this system. I wont go into how to do this now but think about what you would need to do to use the same code to display any section and offer different options.

INK RGB(255, 100, 0), 0
You may or may not realise this but RGB() is a function that converts three numbers into one colour value, yes colours are actually stored as a single number, for example, 255 is bright blue and 65535 is cyan. (Use the search bar to find out how colours are combined into one value if you are interested.)
My point here is that RGB() requires calculation and that means it's slowing down the program unnecessarily, because we could define the colours before the program main begins. Also, what if you decide to change the colours you are using? You'd have to go and change each one by hand! Maybe you want to allow the player to change the colour scheme too.

colorErr = rgb(200,80,0)
colorFG = rgb(200,200,180)
colorBG = rgb(30,30,20)

We could define colours like this. It's best to give the variable a name for what it is used for rather than colour we assign it because the point of a variable is that it can be changed.

Alternatively, we could use an array to store the colours. One advantage of using an array is that we can use a variable to index the array and so use different colours in the same generic template, another level of flexibility. Here's an example comparing variables with an array:
w/variables:
w/array:

Of course I could put the text into an array too and really make this short! This should give you an idea of how to make a generic display system that you can feed data into.

Wow, I'm really writing an essay here!

Going back to your class data:

I see what you are trying to do here but as soon as you start typing the index numbers for the arrays, eg "Classes(2)", you should sense you're doing something wrong. Add some more data for those stats and it gets much simpler:



Formerly OBese87.
Divided
FPSC Reloaded TGC Backer
11
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 17th Nov 2013 07:43
Quote: "
Print " " : Print "You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT."
You can start a string with a space:
Print " You are in a large forest. There is a path to your FRONT, trees to your LEFT and a cave to your RIGHT."
"


The intention of that was to make a new line not a space.

Quote: "
I see what you are trying to do here but as soon as you start typing the index numbers for the arrays, eg "Classes(2)", you should sense you're doing something wrong. Add some more data for those stats and it gets much simpler:
"


Well bugger. It's not the funnest to know your code isn't structured properly. haha I feel like I'm in English class...

Although I love to learn from my mistakes and I will take away as much of this as possible, I was bound to make errors. considering this is my first program I'll take it as a learning opportunity.

Thank you for all your feedback and I'll change as much as I can.

Quote: "
Loop music plays the music, you don't need both these commands. This makes me think you are not reading the help files on the commands you use.
"


Honestly, I just looked up the command and didn't read about it. I just assumed that's what it did. Thanks for picking that up, it was a bug I just didn't worry about.

I will only make necessary changes, only because I am slightly lazy and it's a text adventure so doesn't require a whole lot of optimization. I will leave the GOTO commands where they are because it seems like a significant change to do now considering my whole "game" is based off it.

DividedV -- YouTube Channel

Login to post a reply

Server time is: 2025-05-15 17:19:41
Your offset time is: 2025-05-15 17:19:41