Give me a crash course on randomness please

Marzipan
I started up a little random character generator dealie just for fun a couple of weeks ago, and now I've opened it up and have been just sort of sitting here blankly staring at it awhile. I know exactly what I want the program to do and I feel like I should be able to figure this out, just for whatever reason I'm missing something. Probably something obvious.

I know how to use {random:} in the text processor and that works to a degree, but I want to get more detailed with it. If the generator decides the character is male, for instance, I want it to go next to a set of possible descriptions for facial hair and a slightly different professions list than females would use. (waiter or actor vs waitress and actress, for example).

At one point I had an object called Char with string list attributes like 'eyecolor' 'skincolor' 'haircolor' and 'personality' and 'job' attached, but (and this is probably where that obvious thing I'm missing comes in...) but I couldn't figure out how to tell the game 'okay now go to THIS attribute and grab a random string off it and put it right here.' I couldn't even figure out how to make a command print the description of the Char object when I was working at it from that angle. I assume there's some function or combination of functions that does exactly what I need, but I tend to be pretty hopeless with that kind of thing. I really wish the documentation for them had a few examples...

Anyway, anyone able to help me out here? And please keep in mind I always use the GUI...I've had a bad migraine all day as it it, last thing I need right now is to have to stare at a bunch of code. :P

Marzipan
oh hey this did go through, the forum broke when I tried to post, thought I lost it.

HegemonKhan
Marzipan wrote:Anyway, anyone able to help me out here? And please keep in mind I always use the GUI...I've had a bad migraine all day as it it, last thing I need right now is to have to stare at a bunch of code.


errr..... too late, laughs ... well don't keep reading my post until your migraine is long gone, laughs...

----------

I'm not a coder, so my knowledge is limited, and thus my code method is rather extremely messy~ugly~long ...

it seems like 'delegates' is the way to do this more advanced parsing stuff, as far as I am trying to understand, lol.

-----

my (ugly~messy) way is using lists+dictionaries (you're going to need to read up on 'StringListItem', 'ObjectListItem', 'StringDictionaryItem', 'ObjectDictionaryItem', and~or 'ScriptDictionaryItem' )* :

* or, for another way of returning a Value, simply use Functions (an example):

(you can return any Attribute Type, such as a String, not just an Integer, as is shown in my example below)

player.damage = player.weapon.damage * critical_hit_function

<function name="critical_hit_function" type="int">
if (RandomChance (33) ) {
value = 2
} else {
value = 1
}
return (value)
</function>


lists' + Dictionaries', INDEXING starts at ZERO (and from left to right), not from one:

game.gender_stringlist = split ("male;female", ";")

0: male
1: female

<gender_scriptdictionary type="scriptdictionary">
<item key="male">
show menu ("Hair Style", split ("spiked; mohawk", ";"), false) {
player.hair_style = ToString (result)
}
</item>
<item key="female">
show menu ("Hair Style", split ("ponytail; pigtails", ";"), false) {
player.hair_style = ToString (result)
}
</item>
</gender_scriptdictionary>


game.gender_stringlist = split ("male;female", ";")

player.gender_string = ToString (StringListItem (game.gender_stringlist, GetRandomInt (0, ListCount (game.gender_stringlist) - 1) ) )

invoke (ScriptDictionaryItem (game.gender_scriptdictionary, player.gender_string))


----------

some examples (there's tons of design methods, the above is just a sample only), see if you can understand any of it.

The Pixie
The text processor {random} is definitely not the way here; it produces a different result each time, so your character could be a blond guy when the player looks first, and a brunette woman when the player looks again.

First, here is a function that will take a string of values separated by semi-colons, and pick one at random:
  <function name="Pick" parameters="lst" type="string">
l = Split(lst, ";")
n = GetRandomInt(0, ListCount(l) - 1)
return (StringListItem(l, n))
</function>


I would set up attributes for each aspect, and I would handle sex slight different, as it will have a significant impact on description. Here is some code that you could put in the description. It generates a new description if one has not been made yet, or gives the old one if it has. You can add any number of extra attributes.
if (not HasString(this, "randomdesc")) {
this.female = RandomChance(50)
this.haircolour = Pick("blonde;brunette;fair;black;pink")
if (this.female) {
this.randomdesc = "She has long " + this.haircolour + " hair."
}
else {
this.randomdesc = "He has short " + this.haircolour + " hair."
}
}
msg (this.randomdesc)

Marzipan
The Pixie wrote:The text processor {random} is definitely not the way here; it produces a different result each time, so your character could be a blond guy when the player looks first, and a brunette woman when the player looks again.


Actually my original idea was not to make a character in the game, just to generate ideas for one like at this site or this one. Or something like a Dwarf Fortress description if you've ever played that. I figured there probably was a way to get it to store the random information somewhere as a permanent description, but needed to figure the randomness part out before worrying about the next step. :D

Anyway thanks guys, I'll try out both methods when I get home. And just at a glance I'm thinking 'Pick' will be useful in a lot of situations, I hadn't realized that was a thing.

Though part of the problem with code for me is I'm always slightly at a loss as to where to put it. Pixie, if I read yours right that can just be pasted into the character's actual description?

Silver
The Pixie made a thread on where to put code which might be of help.
viewtopic.php?f=18&t=4771

The Pixie
Marzipan wrote:Though part of the problem with code for me is I'm always slightly at a loss as to where to put it. Pixie, if I read yours right that can just be pasted into the character's actual description?

Yes. If I was creating objects on-the-fly, I would do it at the time they were created.

The Pixie
If you want to get really involved, select randomly from a set of template sentences, and then replace tokens with suitable values. Templates might look like this:

She was a %gen% woman, with %hairtype% %haircolour% hair, and %oddity%.
A %haircolour% woman, she was %gen% and had %oddity%.

You would then replace %haircolour% with a random hair colour.

I would guess that is how this generator works:
http://www.springhole.net/writing_rolep ... origin.htm

Marzipan
The Pixie wrote:If you want to get really involved, select randomly from a set of template sentences, and then replace tokens with suitable values. Templates might look like this:

She was a %gen% woman, with %hairtype% %haircolour% hair, and %oddity%.
A %haircolour% woman, she was %gen% and had %oddity%.

You would then replace %haircolour% with a random hair colour.


Okay, yes, I can work with this. Not familiar with the term tokens but it looks more like what I'm used to when it comes to printing a variable or attribute.

And so would I use Pick as in your earlier example but have it choose from a list of differently structured sentences, tben use it again to replace each of the tokens?

...dammit I really want to go home and try this now. Stuck here for another 6 hours though. :(

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums