creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
hack shack | script reservations | dev resources | dev forum

  

Randomly choose from A-Z?  on 3/14/2018

Hello,
     Is there a way to force something to choose randomly from A-Z, rather than 0-26?
- Malkin


Dear Malkin,
     Test
- Pilla
 
 
Papriko | 5/20/2018  log in to like post  2

I did something similar for the corpse piece vendor. It uses pretty much exactly that method with the CHAR command. I combined that with a wiki article about sprite naming conventions and made a code that continuously spits out theoretically valid sprite names.
With the... I think it was SNAX command, you can check if your sprite really does exist.

EDIT: Oops, didn't realize the comment would appear on top. I thought it'd be appended to the answer. Sorryyy!
 
Pilla | 5/20/2018  log in to like post  1

Hey Malkin!

The CAOS command RAND var1 var2 can be used to pick a random number between var1 and var2.

There isn't a command to pick random letters though, so you would have to pick a random number and convert that number into a letter.
You could just pick a random number between 1 and 26 and then do something like:

doif va00 eq 1
sets va01 "a"
elif va00 eq 2
sets va01 "b"
elif va00 eq 3
sets va01 "c"
.
.
else
sets va00 "z"
endi


Surely there should be a cleaner/easier way!

Recently I learned more about the CHAR variable thanks to Amaikokonut’s blog post at Naturing :: Nurturing.
Char has two commands: one that returns an ASCII code of a character and one that sets a character in a string. The one setting a character is interesting because ASCII code is just a number, and numbers can be randomized with RAND, so...



To set a character, you have to use the ASCII code of that character. If you run the number that corresponds to the correct character through the CHAR command, you will get a string with that character.

Now all that’s left is to figure out the ASCII code of the characters you want to use. I quickly googled the ASCII table and I found that for the characters A to Z, the codes are 65 to 90. For the characters a to z, it's 97 to 122.

So if you want a character between a to z, the resulting code would be this:

char va00 1 rand 97 122


Neat huh?


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
2 online
Furball
Namiraja
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki