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 / Help with a simple text game.

Author
Message
Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 23rd Sep 2006 19:40
Hey, I'm currently making a simple text based adventure game...like the classic "Advent".

I'm a complete n00b at B.A.S.I.C

I know how to link input choices to subroutines and IF statements, but what I'm wondering how to do, is inputting a specific word that can be recognised. The game will recognise certain words like if you type in "break chain" at a specific point, it will recognise this and be able to go to a subroutine, I hope I'm making sense, my explanation isn't the best, I admit.

Can someone please help me to allow the player to type something in that will affect the game like this? thanks!

D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 23rd Sep 2006 20:07
There are various ways to handle this. I'm sure you will get several examples
posted here. My code below only handles the basic logic. There is not much in
the way of error handling, data formating, program setup, or anything else.

Very basic example:


If you are familiar with arrays, you can use them to store your word table
that would be recognized from user input.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 23rd Sep 2006 21:22
You could try using the right$ and left$ commands to check if a string starts or ends with a certain word.



Confucius Say...Programmer who makes genetic programming system loses job
Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 23rd Sep 2006 22:53 Edited at: 23rd Sep 2006 23:19
ah, I tried something very similar to that actually ... but I think I made a small mistake, thanks guys...both examples are actually really helpful

One more thing...how do I stop the program from terminating if something other than what should be entered is entered?

how do I get it to go back to the choice...thanks.

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 24th Sep 2006 01:03
I would just change a variable if something happens, and have the inputing in a while loop based on that variable.



Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 24th Sep 2006 02:54
I'm not honestly familiar with the "while" command at all....would you mind explaining how it works in your example? I have got it to work in my programming, but I'd like to know how it works.

thanks for your help.

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 24th Sep 2006 03:26
I would tell you that you can view the help files by hitting F1, but after looking at what it says under the "while" command I can see that it will not help much.


"while" works similar to "if" in that it will not run the code between "while" and "endwhile" if the condition after the beginning command is not true.

The difference is that in an "if" statement the code is run once if the condition is true. In a "while" statement the code is run until the condition becomes false.

I tried to explain it with this code-


Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 24th Sep 2006 15:30 Edited at: 24th Sep 2006 15:31
If you are using Pro, I think it would be bettter to use the repeat until loop in a situation like this. In this kind loop the condition is at the bottom, so the loop will always run at least once (or more if the condition if false), which is exactly what you need.



You can really do it either way, I just use it this to make sure the loop runs at least once.

Also, you want to give each action a different number, if you use the same for two actions your code wouldn't know which one it is.

Confucius Say...Programmer who makes genetic programming system loses job
Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 24th Sep 2006 15:48
ahh, thanks for the explanation. I understand now

Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 25th Sep 2006 14:41
sorry for the double post....but I have found myself slightly stuck....can someone please look at my coding and help me see what's wrong?

The problem is, after finding a key in desk1, the game instantly goes to the subroutine first_door



Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 25th Sep 2006 15:21
Maybe its because you didn't put "return" after the breakshackle routine.

Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 25th Sep 2006 17:25 Edited at: 25th Sep 2006 17:38
ahh, of course, thanks....I didn't notice that.

*edit* grr, I've done that....and it takes me to the throw_rock subroutine :S



Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 25th Sep 2006 23:50 Edited at: 1st Oct 2006 18:56
When you return to break_shackle from desk1, the while loop sees that action=1 and returns to the wake_up, and its while loop sees that action=1 and exits the while. The program then drops down into throw_rock.

If you made these subs into functions, DBP will automatically find mistakes like this.

Also, you don't need two returns in desk1.



Kenomica_deleted
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 26th Sep 2006 03:30 Edited at: 26th Sep 2006 03:43
What do you suggest I do?

I don't quite get what you mean about turning subs in to functions...but I do understand why the program is going wrong...I just don't get how to fix it lol >_<

I tried setting action back to 0 in search_desk...but it didn't work.


Oh and Code Dragon, sorry, I didn't notice your earlier post..it was good avice too lol

Login to post a reply

Server time is: 2024-09-25 09:37:42
Your offset time is: 2024-09-25 09:37:42