Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: Where to begin with programming this?  (Read 2611 times)

SeriousConcentrate

  • Bay Watcher
  • The Hollow Street Hero
    • View Profile
Where to begin with programming this?
« on: February 23, 2013, 10:35:48 pm »

I suppose first I had better give a little background. I have almost zero programming experience - absolutely zero if one doesn't count some experience with the RPGMaker series. My goal is to create a program that will assist me in character/NPC creation by generating random numbers to get words from a series of tables and - hopefully, if at all possible - save the results as a separate text document. Otherwise, just printing them out for me to review would be enough but not preferable. I would want the results ordered something like this:

Quote
I am (male/female).
I am (fantasy race). (This is probably optional since it might not ever come up depending on what I'm wanting the character for.)
I am X years old. (If I could relate that to race in some way if I do use it, that would be nice. If not, I suppose just making a standard range would be fine.)
I am X inches tall and Y pounds. (If I could somehow relate these to gender, age, and/or race, that would be cool; if not, I could probably just do that manually each time.)
My hair is (color) and (length descriptor). My eyes are (color). My skin is (tone).
My best physical quality is (quality). My worst physical quality is (quality).
My best mental quality is (quality). My worst mental quality is (quality).
I am (descriptor) at (skill). (Probably a few lines of these - between three to six.)
I own a (quality) (item). (Probably a few lines of these as well.)

I heard Lua mentioned in the other Beginner's Programming thread and I'm taking a look at Python right now, but what's the best and/or easiest programming language to learn for what I'm attempting to do? I mean, I don't want anyone to do it for me, I want to learn how to do it myself so I can change, add, or modify things as necessary... although I wouldn't mind a few pointers to get me started. XD Anyway, thanks for reading the topic, even if you don't have any advice.
Logged
SerCon Shorts: This Is How You Do It - Twenty-three one minute or less videos of random stupidity in AC:U, Bloodborne, DS2:SotFS, Salt & Sanctuary, and The Witcher 3.

TomatoWalrus

  • Bay Watcher
  • I am one of the tomatos.
    • View Profile
Re: Where to begin with programming this?
« Reply #1 on: February 23, 2013, 10:43:08 pm »

I only have (minor) experience with C++, but that sounds like it would be easily do-able with C++. Granted, it's probably not the easiest, so you may want to look at Python or Ruby for what you want, but here's a beginners C++ guide:

http://www.learncpp.com/
Logged
I am he as you are he as you are me and we are all together.

lordcooper

  • Bay Watcher
  • I'm a number!
    • View Profile
Re: Where to begin with programming this?
« Reply #2 on: February 23, 2013, 11:06:24 pm »

Couldn't you just roll a dice?
Logged
Santorum leaves a bad taste in my mouth

SeriousConcentrate

  • Bay Watcher
  • The Hollow Street Hero
    • View Profile
Re: Where to begin with programming this?
« Reply #3 on: February 23, 2013, 11:34:08 pm »

It's true, I could, but I would rather take the time to learn how to make something like this. If I can do it it would be a nice utility for myself and anyone else who would want it, I would have the satisfaction of having made something useful, and in the end it would probably be a lot less work to just click a button or two and get a character sheet than it would be to roll a bunch of dice twenty or thirty times, look up the tables to see what the result means, and type it into a text document myself for every NPC I would need.
Logged
SerCon Shorts: This Is How You Do It - Twenty-three one minute or less videos of random stupidity in AC:U, Bloodborne, DS2:SotFS, Salt & Sanctuary, and The Witcher 3.

freeformschooler

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #4 on: February 24, 2013, 12:21:58 am »

I could tell you how to do it in Flash but I doubt that would help.

Basically, though, you'd have an array of possible values for each of the descriptors you're looking for, and a variable for each of those descriptors (probably called a "string" in most languages). Once you've got a random number generation function set up (if your language/api doesn't include one already), you'd take the maximum length of the array and generate a random number between the 0 and said length. Then you'd assign the descriptor from the generated value in the array to the appropriate variable.

Repeat for each descriptor you need then print the variables in the appropriate place when printing the final text output. Not sure if this is how you do it in every language, but it's the general idea.

EDIT: I could just make it for you if you wanted.
« Last Edit: February 24, 2013, 12:27:45 am by freeformschooler »
Logged

SeriousConcentrate

  • Bay Watcher
  • The Hollow Street Hero
    • View Profile
Re: Where to begin with programming this?
« Reply #5 on: February 24, 2013, 12:32:33 am »

I appreciate the offer, FF, but like I said in the OP I'd prefer to learn how to make it myself. ^^^; Anyway, I get the gist of what you're saying (linking words to a numbered list and choosing by random generation was my idea for doing it), but I don't have the knowledge to actually do it.
Logged
SerCon Shorts: This Is How You Do It - Twenty-three one minute or less videos of random stupidity in AC:U, Bloodborne, DS2:SotFS, Salt & Sanctuary, and The Witcher 3.

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: Where to begin with programming this?
« Reply #6 on: February 24, 2013, 12:34:51 am »

You should probably start with the absolute basics of the language first, so you don't overwhelm yourself. Here is a semi-decent tutorial on Python that will be a good starting point.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

freeformschooler

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #7 on: February 24, 2013, 12:36:23 am »

You should probably start with the absolute basics of the language first, so you don't overwhelm yourself. Here is a semi-decent tutorial on Python that will be a good starting point.

Yeah, if you want to start from near-zero and learn how to do it yourself, this is an absolute must. Starting on a project bigger than your skill level is just a recipe for burnout.
Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #8 on: February 24, 2013, 06:26:31 am »

You need two lines of python experience to do something like this.
Code: [Select]
gender = raw_input("I am (male/female): ")
race = raw_input(" I am (fantasy race): ")
####
print("You are a " + gender + " " + race)
[\code]

so yeah, go to python and install it.
It preinstalled on most linux distros today, so if you are using linux you already have it.
Start coding. Direct any question to google.
Logged
Merchants Quest me programming a trading game with roguelike elements.

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: Where to begin with programming this?
« Reply #9 on: February 24, 2013, 07:33:58 am »

-snip-
Except your code allows user to choose gender and race*, whereas OP wanted the program to  randomize them. Your code also would allow any string to be gender and race*.

*If I can read Python correctly with no knowledge of the language.
Logged

Imperfect

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #10 on: February 24, 2013, 07:54:50 am »

You need some strings to form the framework of the output(the stuff that is the same every time), then a bunch of various things that you intend to be picked at random stored in their respective lists(list of races, list of professions, lists of hair colors, etc.), and a function to pick a random item from a list; it should be implemented in Python, you don't need to go around by selecting an element based on a randomly generated number. Then you have to cobble it all together with pluses and then do something with the output. I don't know right off the bat how to store the results in a separate file, but the answer to a lot of programming related questions can be found by searching for "how to [do something]/what does [something] mean in [the language you're using]". Chances are that people had this problem before, and the first thing that usually pops up is an answered question on stackoverflow.com on a very similar issue.

If you have very little programming experience, I'd recommend taking a beginner level programming course, for example the one I study right now, the Introduction to Computer Science course at udacity.com, which obviously gives you some insight into computer science, but also teaches you quite a bit about Python. A generator you describe is a fairly simple affair to pull off; in fact, I tried to do something similar(except I wanted mine to generate titans) in a sudden burst of need to somehow put my so far very limited understanding of Python into actual use. Watch out for spaces and also for grammar.

Here's what I managed to write before I lost a lot of unsaved work to a computer crash and abandoned the thing. It's "inspired" by the bronze collosi and forgotten beasts generator of DF, I even copied the list of metals from DF wiki, as I never plannd to release this anywhere. The program is short, incomplete, and some things are more complicated than need be, but just to give you a picture of what a generator looks like and what complications grammar can pose.

Hope this helps!

Code: [Select]
from random import choice

#Name = [name, adjective]
aluminum = ['aluminum', 'aluminum']
bismuth = ['bismuth', 'bismuth']
copper = ['copper', 'copper']
gold = ['gold', 'golden']
iron = ['iron', 'iron']
lead = ['lead', 'leaden']
nickel = ['nickel', 'nickel']
platinum = ['platinum', 'platinum']
silver = ['silver', 'silver']
tin = ['tin', 'tin']
zinc = ['zinc', 'zinc']

metals = [aluminum, bismuth, copper, gold, iron, lead, nickel, platinum,\
 silver, tin, zinc]

primeval_origins_existence = ['has existed since', \
'has wandered the world since', 'has been living since', 'was created in',\
'was born in', 'is an ancient being from', 'is an embodiment of a spirit from']

primeval_origins_age = ['an era', 'a time', 'an age']

primeval_origins_age_desc = ['that is not ours', 'other than ours',\
'long gone', 'long forgotten', 'long before recorded history',\
'that better be forgotten', 'different from ours', \
'lost in the mists of time']

def gen_ran_titan(): return str('He is a ' + choice(metals)[1] +\
  ' titan. He ' + str(choice(primeval_origins_existence)) + ' '+\
   str(choice(primeval_origins_age)) + ' ' +\
    str(choice(primeval_origins_age_desc)) + '.')

print gen_ran_titan()
Logged

Dorftrottel

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #11 on: February 24, 2013, 09:14:11 am »

Working with strings? Easy? Perl!
Okay,okay,python and lua will do the trick less messy, but I still can't resist recommending perl here.

I know you want to do it yourself, which is excellent, but just to demonstrate the power of perl, here's a part of your program in a one line of code:
printf "I am a %s %s \n", qw(male female)[rand 2], qw (human goblin lumberjack)[rand 3];

a more generic approach would be:

@race = ('human','goblin','lumberjack');
@gender = ('male','female');
printf "I am a %s %s \n", $gender[rand int(@gender)], $race[rand int(@race)];

If you are interested in learning programming beyond your project, i recommend reading through some of the programming threads in the forum, like the recent beginners programming question: http://www.bay12forums.com/smf/index.php?topic=122911.0

Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: Where to begin with programming this?
« Reply #12 on: February 24, 2013, 10:20:06 am »

Except your code allows user to choose gender and race*, whereas OP wanted the program to  randomize them. Your code also would allow any string to be gender and race*.

*If I can read Python correctly with no knowledge of the language.
*

I misunderstood, I thought he wanted to be able to write what he was. My bad. Python is still stupid easy to use for something like this.

Either way, while it is easy to learn, it is a bad language for anything big. It is a pain to debug. For something like this it is perfect.
Logged
Merchants Quest me programming a trading game with roguelike elements.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Where to begin with programming this?
« Reply #13 on: February 24, 2013, 06:16:41 pm »

Ok what you are asking for is not only easy, but very easy. Any half decent programming language would do, so go for something higher level. C++ is using a chainsaw to file a nail. Go with python.

shadenight123

  • Bay Watcher
  • Death. To all. Except my dwarves.
    • View Profile
    • My Twitter
Re: Where to begin with programming this?
« Reply #14 on: February 24, 2013, 06:20:30 pm »

or there's also java.
*Hides before getting flailed alive*
which has the 'random' to generate...random numbers.
Logged
“Well,” he said. “We’re in the Forgotten hunting grounds I take it. Your screams just woke them up early. Congratulations, Lyara.”
“Do something!” she whispered, trying to keep her sight on all of them at once.
Basileus clapped his hands once. The Forgotten took a step forward, attracted by the sound.
“There, I did something. I clapped. I like clapping,” he said. -The Investigator And The Case Of The Missing Brain.
Pages: [1] 2 3