Random Colour code

A place to suggest new commands, feats, skills, ...
Post Reply
User avatar
Jarngron
Sword Journeyman
Sword Journeyman
Posts: 131
Joined: Tue Mar 29, 2016 2:21 am

Random Colour code

Post by Jarngron » Mon Aug 29, 2016 8:51 am

While making 'a piece of saltwater taffy' I had the idea of using a single random colour code for 'taffy' to help describe the many colors that all tasted the same.

When I checked, I didn't see any functions to do this. Used sparingly this can be fun, used too much it's an eyesore - but I could say the same of colour codes in general.

Can anyone else think of fun ways to use a random colour code?
Cattle die
kinsmen die
all men are mortal.
Words of praise
will never perish
nor a noble name.

- Hávamál
User avatar
Larethiel
Sword Grand Master
Sword Grand Master
Posts: 910
Joined: Sat Jul 22, 2006 4:10 pm
Location: Mt. Whateverest

Re: Random Colour code

Post by Larethiel » Mon Aug 29, 2016 10:05 am

Are You looking at using a rand_prog or just General ideas?
Weit in der Champagne im Mittsommergrün,
dort, wo zwischen Grabkreuzen Mohnblumen blühn,
da flüstern die Gräser und wiegen sich leicht
im Wind, der sanft über das Gräberfeld streicht.
User avatar
Harroghty
Staff
Staff
Posts: 9695
Joined: Tue Jul 27, 2004 5:38 pm

Re: Random Colour code

Post by Harroghty » Mon Aug 29, 2016 1:06 pm

There are several candy objects in the game which are styled as bags of candy, and a PC can use a command (e.g. get taffy bag) to produce a finite number of edible pieces (the total count can be governed, if desired, by value5). In this case, one could include an if rand check in the intercept program to vary colors.

Code: Select all

>intercept_prog get~
if stringprefix($2) == bag
  if stringprefix($1) == taffy
    if objval5($o) > 1
      mpoload 1234
      if rand(50)
        mposet i1234 short {90}a piece of taffy
      else
        mposet i1234 short {A0}a piece of taffy
      endif
      mpgive i1234 $n
      mpoadd on $n $o value5 -1
    else
      mpechoat $n {90}The bag is empty.
    endif
  else
    mpunintercept
  endif
else
  mpunintercept
endif
~
|
Alternatively, you could junk the bag on the last candy by adding a little check at the end.

Code: Select all

if objval5($o) == 1
  mpechoat $n You finish a bag of candy.
  mpechoaround $n @N finishes a bag of candy.
  mpjunk $o
endif
"A man may die yet still endure if his work enters the greater work, for time is carried upon a current of forgotten deeds, and events of great moment are but the culmination of a single carefully placed thought." - Chime of Eons
User avatar
Jarngron
Sword Journeyman
Sword Journeyman
Posts: 131
Joined: Tue Mar 29, 2016 2:21 am

Re: Random Colour code

Post by Jarngron » Mon Aug 29, 2016 6:45 pm

I really like the way you think, Harroghty. Thank you very much for the assist.

Well Larathiel, I was just thinking I could use a regular ansi colour code that would randomly return a color, that the average end user could also potentially use - and I don't know if that -is- the best idea given how gaudy those random colors can look in many cases. Either way, this will suit me just fine, I planned on having players pull a piece from a box with an intercept to cut down on unnecessary nesting.
Cattle die
kinsmen die
all men are mortal.
Words of praise
will never perish
nor a noble name.

- Hávamál
Aysa
Sword Grand Master
Sword Grand Master
Posts: 266
Joined: Sun Jan 26, 2014 9:37 pm

Re: Random Colour code

Post by Aysa » Tue Oct 04, 2016 12:46 pm

I am not a programmer. I try to avoid programming at all costs; however, if you are worried about gawdy colors in your randomized programming... could you not just run the randomizer, assigned the result to a value.

If value < 20 ... then color is super cool looking blue color
If 21 < value < 40 ... then color is super cool looking red color
... and so on.

Again, I might be barking up the wrong tree or might be creating needless routines just so someone can randomly pull a butterscotch flavored candy one time and then a cinnamon flavored candy the next.

Do not mind me. I will go back to OCDing on color schemes in my outfits.
Areia
Sword Grand Master
Sword Grand Master
Posts: 493
Joined: Fri Feb 12, 2016 11:11 pm

Re: Random Colour code

Post by Areia » Tue Oct 04, 2016 2:23 pm

Aysa wrote: ... could you not just run the randomizer, assigned the result to a value.

If value < 20 ... then color is super cool looking blue color
If 21 < value < 40 ... then color is super cool looking red color
... and so on.
Assuming I read and understand your idea correctly, that is essentially what Harroghty proposed above, just in simpler terms (because coding out even the simplest problems in most any scripting or programming language just has to look waaaayyy more complicated than necessary ;). The largest difference being that your example stores a random value in a variable and then makes various if-checks on that variable, whereas Harroghty's is pretty much just cutting out the variable middle man (area code cannot make use of variables). But yeah, both would end up with the same effect. :D
Nascentes morimur, finisque ab origine pendet.
Post Reply