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.

Author
Message
sheffieldlad
9
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 17:38
Hi all,
I'm a novice at this.
I'm looking to take input from a user



split the string into seperate words (using token$ with " " as the delimiter?)

store them in an array (no idea how to do this)
and compare them to several lists of words, doing other stuff if a match is found.

I've been searching the forum for hours and I just can't seem to make anything work how I expect it to.

Could someone explain how i could do this please?

Many thanks,

Paul.
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Apr 2012 17:50
Well, here's a stab at it. Sorry, I don't have time to type up a full example, but this should get you started.

First off, we have the string answer$ that needs to be broken into separate words. For this I would suggest scanning through it with a repeat/until loop character by character until you reach the end, like so:


What this will do is go through it until it finds the " " character, then store that character's location into an array named Breaks(). You can then use the Left$() and Right$() functions to grab the string of characters between the breaks.

That kind of spilled into your next question: Arrays.
To declare an array, you use the DIM command. You can dimension them up to, I think, 255 levels. In this case, you will probably want a string array, so you would use:

DIM CommandArguments$(10)

Note that this assumes that there is a max of 10 different arguments that the user can enter (all would be separated with a " "). Tying into the previous example:



Yeah, it's a little flawed, in that I was too lazy to put the code to extract the middle of a string (it's not hard, you can either get clever with the left$() and right$() commands or write a function that simply uses mid$() and adds all the appropriate characters together).

For comparison, I would suggest using an array that is loaded either with a file (OPEN TO READ) or that is just saved and loaded (SAVE ARRAY and LOAD ARRAY, respectively).

Hope this helps!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
sheffieldlad
9
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 17:55
Thanks for the reply.
It's along the lines of what I am looking for but I think I'll have to read it over a few times till it sinks in.

ould I be better doing something along the lines of letting the counter run then....



to setup the array based on the amount of seperate words I intend to store.
I imagine I would have to inc the counter by 1 to account for the fact there should be one more word than there are spaces?

Thanks again,

Paul.
sheffieldlad
9
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 18:16
Here is what I have so far.



It takes input, counts the number of words (adding one at the end of the count because there is no space at the end of the input line, flawed I know because if someone comes along and adds a space to the end of the input they type I will have 1 spare space in my array. Not the end of the world but sloppy...)

It prints the word count then uses token$ to split the string into words.
I don't understand how to add the words to an array.
sheffieldlad
9
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 21:25 Edited at: 16th Apr 2012 21:31
I figured out how to add them to an array (yay)

here is my source:



Does it look ok or is there a better way?

Now I have to work out how to pass the array to my list of words and check for matches.

Although it's tough going for me I am enjoying it

I guess now it's a matter of saving the array and loading it with my function to check the word lists?

Many thanks for your help bn2

[edit]typo[/edit]
sheffieldlad
9
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 22:38
It just occured to me that I posted this on the wrong board.
I've made a new thread on the newcomers board.
http://forum.thegamecreators.com/?m=forum_view&t=196021&b=7

sorry :/

pogo: http://dl.dropbox.com/u/65597655/pongo.zip
Breakout clone: http://forum.thegamecreators.com/?m=forum_view&t=185535&b=6

Login to post a reply

Server time is: 2020-08-05 09:25:55
Your offset time is: 2020-08-05 09:25:55