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 / Options from text file

Author
Message
mad computer user
15
Years of Service
User Offline
Joined: 9th Nov 2008
Location: New Zealand
Posted: 18th Jun 2010 07:13 Edited at: 18th Jun 2010 07:20
Hi

iv made a script and its all working, but wondering, is there any way to make it easier to add all the adjectives/nouns to the code rather than typing each one in by hand? as i have over 500 adjectives i want to add and almost as many nouns... would it be possible to read it from a text file? like each line of a text file is a different option it could be?

heres the code currently:


thanks
Keeghan

p.s thanks to all those who helped me get the script to what it is currently in the other thread, much appreciated
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 18th Jun 2010 14:32
It's possible and recommended, but first it's important that you learn about arrays. There is a tutorial in the Tutorials Thread at the top of this board.

"everyone forgets a semi-colon sometimes." - Phaelax
nitrohaze
21
Years of Service
User Offline
Joined: 21st Apr 2003
Location:
Posted: 18th Jun 2010 15:52 Edited at: 18th Jun 2010 15:54
MCU

Hope this helps, as Zotoaster says arrays are the key, you could also read the information from a file rather than using data statements (but thought I would leave you with something to do). Using data statements for now lets me easily demonstrate arrays and how they tie into the program, if you hit a blank with using a file give me a shout and I will try to help although am not on the forums every day. I have commented out your image code, but you can simply put these back in.

Its fully commented, hope it helps.


mad computer user
15
Years of Service
User Offline
Joined: 9th Nov 2008
Location: New Zealand
Posted: 18th Jun 2010 23:22
ok, amazing that makes sense. But would that still mean i have to add a whole bunch of words to the script which is what i was trying to avoid? admittedly its easier if i can just add "", around each one but still not quite what i was going for...
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 19th Jun 2010 05:24
It really depends.If you are making word involving game like scrabble for example then is unavoidable to write all the words.You must include them somewhere, the game won`t just magicly knows them.Well if the game is gonna be scrabble you`ll probably look at some way to port whole electronic dictionary in your own file format, instead writing words by hand.

Is it possible for you to illustrate what are you exactly intedning to do with all this words?What kind of game are you making, how the words are involved there?

I`m asking this because i`m not much of a code reader.Eventually i`ll check your code snippet but in the process my brain start hurting sometimes and i try to avoid this as much as possible.

In the same time is allways good to inform people what you intend to do with this so there could be someone which can lead you to better,faster more sufficient way to do it.It`s like a case i`ve seen allready.Someone ask for help about code he can`t run, something from code snippets for example, there are people which assist him and in the end the guy is able to compile.And he realise that this code can`t help to achieve his goal.I don`t say that this is the case, just want to be clear on that!

My point is that if we know what stays behind the adjectives/nouns then we can provide more alternatives.Some better some worst and some irrelevant as allways.For now i see from your code that your adjectives+nouns produce sentences, which if there is allways 1st adjective and 1st noun, 2nd adjective and 2nd noun...and so on until very end, it`s pointless!It can be just sentences which combine the words from both they can be stored in 1 array instead of 2.It`s completely diferent story if you randomize separately adjectives and nouns.It think it might be the case because you didn`t disagree with nitrohaze`s example, just wasn`t much pleasent with the way you need to build all this.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
mad computer user
15
Years of Service
User Offline
Joined: 9th Nov 2008
Location: New Zealand
Posted: 19th Jun 2010 06:32
well im making a title generator, so it picks a random adjective and a random noun and puts it inf ront of "The", and makes a title.

I got nthe idea off a website and thought itd be a good way to get back into DBP coding. At the moment i actually have all the words i need in the program, so its fully working etc, but id like to have them in a external text file so that others can add words they want, maybe sentences or something, plus itd be tidier code. Iv attached an installer for the program as it is now to show you what the program does.

Hope that helps

Attachments

Login to view attachments
nitrohaze
21
Years of Service
User Offline
Joined: 21st Apr 2003
Location:
Posted: 19th Jun 2010 12:12 Edited at: 19th Jun 2010 13:17
luskos

Quote: "It think it might be the case because you didn`t disagree with nitrohaze`s example, just wasn`t much pleasent with the way you need to build all this."


Was merely providing and example using MCU's structure where possible so that he could learn from it. Rather than re-writting the whole code.
nitrohaze
21
Years of Service
User Offline
Joined: 21st Apr 2003
Location:
Posted: 19th Jun 2010 13:21 Edited at: 19th Jun 2010 13:28
MCU


I hope this helps, It is using your code as much as possible. If you create 2 text files (nouns.txt, Adjectives.txt) which contain the appropriate data. Put each word on a single line in the file.

Alter the lines below to reflect where you have saved them on your system.

Num_of_Adj=Count_Lines("C:\temp\adjectives.txt")
Num_of_Nou=Count_Lines("C:\temp\nouns.txt")

Alternatively simply download and extract the attached file into your C:\temp directory and it will work out out of the box, with the source code below.



The following code should help you. I have removed my original comments and put new ones in where I have added further code.

There is a reusable function that might come in handy in the future.

BTW: You should be able to find lists of nouns and adjectives on the internet to save you hours of data entry! just a bit of formatting needed.



Attachments

Login to view attachments
mad computer user
15
Years of Service
User Offline
Joined: 9th Nov 2008
Location: New Zealand
Posted: 19th Jun 2010 14:44
thank you so much, right now im going to bed but in the morning ill make the 2 text files and post the results.

Login to post a reply

Server time is: 2024-09-28 18:24:27
Your offset time is: 2024-09-28 18:24:27