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 Discussion / Text Baseball-Input not responding, just a quick question

Author
Message
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 25th May 2007 09:04 Edited at: 25th May 2007 09:25
Hello all, this is the start to my text baseball game and as the subject indicates, the input is not printing what I thought i was prompting it to. I'm not stumped, just confused as I thouht I had input commands down. Can anyone here please tell me what I did wrong please? It would be most appreciated. Thank you.



I even wrote psuedocode for this one, something i never do.

Figures huh, I figured out what the problem was, I'm sorry about wasting space. If a mod happens upon this, you guys can lock it.

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th May 2007 09:34 Edited at: 25th May 2007 09:35
Hello Zombie,

Looks like you mixed up your variables a bit. You're asking for input of a string but you are testing the results of a number:



In this case, I think you mean option to be numeric so it should read as option and not option$ after the input command. If you want to test a variable, the variable and the test have to be of the same type (string, number, etc).

Enjoy your day.
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 25th May 2007 21:32 Edited at: 26th May 2007 04:36
thank you latch, will make the change now. Thank you again for your help. Okay, here is the basic skeleton I have for the game, I'm working on getting different conditions. I'm still having trouble with it, but its a work in progress. Commets? Its my second program I've ever written gamewise.



Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th May 2007 10:23
A couple of pointers,

You seem to be using a lot of variables as flags (indicators that a choice or action has been performed), maybe more than you need. While this is ok, it can become hard to manage as the program grows. An alternative is to use arrays and data statements. A single array can behave as if it is several variables of the same type. And if you are going to assign values to your variables by hand, a good tool for that is data statements. The two work well together and can give your program some order and easier manageability. Here's a short example:



Enjoy your day.
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 26th May 2007 14:44
Thanks Latch, I was actually doing a tut and working with examples of arrays. I've read through your example and have a quick question before I go to darkedit and begin working.

rem the flags (numbers) that may go along with the titles
data 6,12,36,48/code]

I don't understand about the data statement, what are the numbers representing. Just want to be totally clear on it. Thank you for taking the time to write out the example though, I know it will come in good use.

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 26th May 2007 15:26
they are being fed into the arrays with the read command.





the dollar sign denotes a string or word.
so now latch's action$() array would appear to be this.

action$(0) = nothing, not being used or filled
action$(1) = "Single"
action$(2) = "Double"
action$(3) = "Triple"
action$(4) = "HOMERUN!!"

if you print them with a loop you will see the results, the other array is being fed numerical data.
Have a look at the next one now you know how this one works.

Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 26th May 2007 20:39
Alright cool, thank you for that. I'll be off to creating now .

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th May 2007 03:37
The actual numbers in the data statements are just examples of values that could be paired with the text. Like Indi was describing, when someone makes a choice, 1,2,3 or 4 is selected. The values of the text are stroed in an array at positions 1,2,3 and 4. There are also numbers stored in another array, actiondata(), at position 1,2,3 and 4. So, when choice is assigned a value when a user picks it, that value is put in both arrays to retrieve the appropriate text value and the appropriate number value.

So if a user chose 3, then the text value returned is "Triple" and I assigned a value of 36 - I just picked numbers out of the air. It's value would only be important to how you would use it in the program. For example, perhaps this value is passed to a statistics routine that keeps track of which team has the highest hit record, or maybe it is a timer value that counts down until 0 giving the batter time to run as far as they can around the bases. It's just meant as an example to show how you can load your arrays with data and how to access the values in them with a single input.

Enjoy your day.
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 27th May 2007 12:47
Alright then, thank you Latch. I'm going to go off to work on it, I'd love to put in a stats board. When i'm watching sports I can't help but keep my own stats, I love the management aspects. Thanks again for taking the time to explain this to me, the same goes for indi as well to stop in his day and help me out.

Thank you both again, have a good one guys.

zombie

Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 30th May 2007 21:03
Thanks a lot guys, the arrays are working out great, but i've run into another little speedbump that i need a second opinion on. I've been trying to randomnize the actiondata$ and keep running into trouble with it. Here is what i've tried so far as I just really don't know what to do.



So i'm stuck a little, once it can be random, it can really take shape. I'm still learning arrays, about grabbing from text files and all, but I was wonderinig if i could have some help. Please? I hate to ask so much i want to learn it on my own.

Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 30th May 2007 23:13 Edited at: 30th May 2007 23:14
the rnd() command can only output a integer value between 0 and the number you enter between the brackets.

what your code tels darkbasic to do is return a nuber between 0 and the value in the variable.

what you need to do is calculate a random number, store it in a variable and then see what action corresponds to that number.



I can't say for sure if the code wil output 0 though

Don't look at my sig!
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 31st May 2007 01:25 Edited at: 31st May 2007 03:09
Okay, so i've seen a couple different ways to do this kind of project. Thank you all for your help . I'm going to try both methods and see what I come up with. Thank you latch,indi and you link for helping me out!!! You guys are the best.

I don't know if that would put me right back where i started though, i have to be careful.

Ah yes and the arrays could be almost mini menus in themselves, i wonder could i jump from array to array randomly?? for more depth.

I suppose it would be like taking a regular swing which jumps to another array of possible solutions such as a hit or an out. I think the term would be a sub result of an action.

Here's what I came up with but its giving me an error.


laters,
zombie



I switched it to the actiondata array, but db kept crashing so i stopped.

LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 31st May 2007 04:51
if action$ = "1" then gosub weak_swing2

if action$ = "1" then print "you pop up to the first baseman."

Since you are using action$ as a string, you need to enclose the result to test against in quotes.

LB
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 31st May 2007 05:27
grrr...this sucks, it keeps crashing on me, and i don't know why.

LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 31st May 2007 05:32 Edited at: 31st May 2007 05:32
I didn't catch it earlier, but you have an if / then statement within an if / endif.

It should be:


LB
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 31st May 2007 06:51 Edited at: 31st May 2007 15:04
Nice dude, thank you very much, code is working great now and db isn't crashing. So thank you LBFN,Indi,Latch,and Link for all your help. You guys are the best.
Now all i gotta do is get it to pick randomnly and we're good, but i'm pretty sure i can do that.

Hey i'm still having some trouble with randomizng the options in my subroutine, it just keeps reading out as a hit, didn't know if anyone could give me a hand with that. I've got my code here.
I've tried using greater than or less than, i'm going to give it another shot so i might figure it out.

zombie


Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 31st May 2007 15:21 Edited at: 31st May 2007 16:14




Yea, so i figured out what to do and it will work cleanly with subroutines, thank you all very very much. If a mod is watching this, you may lock it unless the others have some input on it. Thank you guys and I can't wait to finish this, I'll show it to you all when i'm finished .

Here is what i have now, outs and baseman have been added at their most basic form.



Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 2nd Jun 2007 09:28
Well it was bound to happen, i need some guidance on my pitching. The menu comes up,but i'm having some difficulty with the subroutines. you can pick an action thanks to latch and his arrays . but then just a blank screen.



I've already tried two new arrays for my pitching actions and data but i just end up with the black screen of death. Other than that everything is working pretty good. Any help would be appreciated, i may figure it out before then but I would still appreciate it .

slicer 4 ever
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: currently: planet gamma3295
Posted: 2nd Jun 2007 10:35
to me it appears that you clear the screen directly after drawing it so that may explain why you don't see anything

my smiles love me =-)=-)=-)(-=(-=(-=
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 2nd Jun 2007 16:16
Hi Zombie,

The user input is stored in the variable 'choice', but you use the string 'action$' to tell the program which subroutine to be routed to. You need to convert the number in choice to the string action$ [action$=str$(choice)].

LB
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 2nd Jun 2007 16:51 Edited at: 2nd Jun 2007 17:08


Is this what you meant?

I'm going to try it with two new arrays for my pitching.

Here's with new arrays, this really has me turned around.



LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 2nd Jun 2007 18:19
No, that's not what I meant. Here is what I was thinking:


LB
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Jun 2007 18:55 Edited at: 2nd Jun 2007 18:56
@Z

From you code snippet, I don't see any consistency with your variables. What I mean is, you reference 1 variable with one name and type (action$ then pitching$) then another. In all the snippets, there just isn't any consistency. A big thing in programming is organization and variable management. In a 10000 line program, if you are calling a variable named act at line 3678, then later trying to call that same variable at line 7500 calling it action, your program will not behave as you want because they are two different variables even though you intended for them to be the same. Now you'd have to debug and it could be pretty hard.

With that being said, I see this in your code:


You've created two STRING arrays (just making sure you mean them to be strings) one called pitching$() and one called pitchingdata$(). So far that's fine, probably. But then after the variable choice is set by a user, you reference action$(choice) - this is probably ok too because you are using action$(choice) to describe what the user has chosen - but if you menat it to describe the pitch - then it won't work becuase you defined pitching$() to hold that info. And to reference pitching$() you would have to use pitching$(choice).

Onward

A little later you have

If pitching$="1" then etc.

Where did pitching$ come from? Do you realize that this is a different variable than your array pitching$() ? Also, if it's meant to be different, you will confuse yourself because it looks like the array.

Did you perhaps mean to send the choice to the pitching$() array? Something like pitching$(choice)? If so then your IF THEN conditional would make no sense.

I can only guess at your intentions but from the code I see, it's that inconsistency that's making things not work the way you want.

Just a tip, and you probably already know this, but if you want to reference a number, use a number type variable (either an interger or a float) - if you want to reference some text, use a string variable. For example, choice is a number variable. The user will only input 1,2,3 or 4. There's no reason to make it a string unless you want to add it to a line of text. Anyway, the whole point is to ask yourself questions about want you want your variables to do and choose the appropriate one for the situation.

Now back to pitching$ and the IF THEN

As I see it, you are trying to get the users choice and use that to tell what kind of pitch to throw. Remember, the choice the user is making is stored in choice and you want to use that number to send to the approriate pitch routine. You can use the IF THEN you had set up for pitching$ but replace pitching$ with choice and get rid of the quotes around the numbers

IF choice = 1 then gosub pitch_one

If you are going to have a huge list of choices, I'll throw another concept at you that you should go research in the DB help - use SELECT and CASE.

Select and Case are used to sorta "if then" through a list of many choices. Let's say instead of 4 choices for pitches you had 15. You wouldn't necessarily want to write an IF THEN clause for each choice, you would use SELECT and CASE. Here the variable we are looking at is named choice so we start with Select choice


The power of Select Case comes when you have a lot of stuff happen if that particular case occurs. You could cram as much code as you want between CASE and ENDCASE essentially making it a subroutine if you are so inclined.

The IF THEN in you situation may be better because it won't necessarily save on typing to use Select Case.

Enjoy your day.
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 2nd Jun 2007 19:30
I was confused and I wanted to thank you for your insight on this. This is really my first game project and so there is a bunch of things i truly never got to code with, I suppose thats why my code didn't match up.

I will research select and cases. My original intent was for the pitching to act like my batting sequence that you helped me set up. I'll put that up now, its from the start.



And that is how i wanted the pitching to react but as we know, i've hit a bit of a speed bump. I did confuse myself with the array's. I had originally had the two arrays named as action$ but that wasnt working either so i went with pitching$. I'm still a little confused on everything. I'm rereading your post now after this post and then looking up select and case.

I'm still really just learning about arrays and using mulitple variables with my statements so its been a learning experience. I appreciate the time you're taking to help me out. Alright, i'm going to get to work and do some testing.

Thank you for your help latch and lbfn, this pitching routine is my only problem right now, everything else is working great.

Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 2nd Jun 2007 19:45
Latch-Hey thank you very much for explaining all of that. I've reread your post and I understand a little better what i was doing wrong. I wanted to show you though that I have used the case and select and with a few changes i'll be right on track again. Here's the code



Well thank you again and I'm going to be on my way coding now, thank you again latch!! hehe, you help me with practically all of my questions . I feel like you're my teacher .

Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 5th Jun 2007 02:15
grrrr...I shouldn't change things when they are working so well. My batting scheme has gone screwy on me. It will not display the strikes,balls,score,etc... All i did was shift the code a little and i can't find the problem here. I've been messing with it for about an hour now and was wondering if a second eye could see whats wrong. I'm sorry to be a bother, but its whats stopping me from making the next big step, innings. Okay here's the batting scheme.



I'd appreciate any help or advice. Sorry once more and have a good night everyone.
zombie

LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 5th Jun 2007 03:18
Zombie,

At first I thought your outs, homeruns, etc., was not showing up on the screen, but after a second look, I think you are saying that the values are not correctly displaying on the screen.

You are printing the stats before you update them. You shouldn't print the status until they are all updated.

As a suggestion, why not have all of the code associated with a=3, as one example, in one place within an if - endif like this:


LB
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 5th Jun 2007 06:14 Edited at: 5th Jun 2007 06:17
LBFN-I like that idea, i think it will keep me more organized as well since i'm terrible with arrays. Thank you, i'll recode my scheme like that. We'll see what happens .

Login to post a reply

Server time is: 2025-05-28 20:54:20
Your offset time is: 2025-05-28 20:54:20