Assigning hex values from array to character.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
jpalmer999
Newbie
Posts: 6
Joined: Wed Aug 04, 2021 1:40 pm
itch: jonathanpalmer
Contact:

Assigning hex values from array to character.

#1 Post by jpalmer999 »

So I am trying to make an rpg with an alignment bar (blue good, white neutral, red bad) and I have all the values I want set to a string array of 101 values. I then changed the character name color to be equal to the alignment index of the color variable.

However, ren'py brings up an error

Error Information
While processing the color property of anonymous style: line 7, in script player "zzz"
Exception: Color string u'[alignColors[iPlayer_Alignment]]' must be 3, 4, 6, or 8 hex digits long.



I'm rather confused about what is going wrong. As far as I can tell it should work as the value in a character define for the color is a string value anyway.

Thanks for any help in advance,
Jonathan

Initializing the variable

Code: Select all

label start:
    call Levels
    call Player_Init
    call Init_Alignment_Colors
    call Init_Audio
    call Init_Images
    call Init_Variables
    call Init_Video
    call Inventory

    jump Game_Select
Character Defining

Code: Select all

define player = Character ("[sName]", who_color = "[alignColors[iPlayer_Alignment]]")

Array

Code: Select all

label Init_Alignment_Colors:
    python:
        alignColors = [
            "#ff0100", # 0
            "#ff0500", # 1
            "#ff0a00", # 2
            "#ff0f00", # 3
            "#ff1400", # 4
            "#ff1800", # 5
            "#ff1d00", # 6
            "#ff2200", # 7
            "#ff2700", # 8
            "#ff2b00", # 9
            "#ff3000", # 10
            "#ff3500", # 11
            "#ff3a00", # 12
            "#ff3e00", # 13
            "#ff4300", # 14
            "#ff4800", # 15
            "#ff4d00", # 16
            "#ff5100", # 17
            "#ff5600", # 18
            "#ff5b00", # 19
            "#ff6000", # 20
            "#ff6400", # 21
            "#ff6900", # 22
            "#ff6e00", # 23
            "#ff7300", # 24
            "#ff7801", # 25
            "#ff7d0b", # 26
            "#ff8215", # 27
            "#ff881f", # 28
            "#ff8d29", # 29
            "#ff9334", # 30
            "#ff983e", # 31
            "#ff9e48", # 32
            "#ffa352", # 33
            "#ffa95c", # 34
            "#ffae67", # 35
            "#ffb371", # 36
            "#ffb97b", # 37
            "#ffbe85", # 38
            "#ffc48f", # 39
            "#ffc99a", # 40
            "#ffcfa4", # 41
            "#ffd4ae", # 42
            "#ffd9b8", # 43
            "#ffdfc2", # 44
            "#ffe4cd", # 45
            "#ffead7", # 46
            "#ffefe1", # 47
            "#fff5eb", # 48
            "#fffaf5", # 49
            "#ffffff", # 50
            "#f5faff", # 51
            "#ebf4ff", # 52
            "#e0efff", # 53
            "#d6e9ff", # 54
            "#cce4ff", # 55
            "#c2dfff", # 56
            "#b8d9ff", # 57
            "#add4ff", # 58
            "#a3ceff", # 59
            "#99c9ff", # 60
            "#8fc3ff", # 61
            "#85beff", # 62
            "#7ab8ff", # 63
            "#70b3ff", # 64
            "#66aeff", # 65
            "#5ca8ff", # 66
            "#52a3ff", # 67
            "#479dff", # 68
            "#3d98ff", # 69
            "#3392ff", # 70
            "#298dff", # 71
            "#if88ff", # 72
            "#1482ff", # 73
            "#0a7dff", # 74
            "#0077ff", # 75
            "#0072ff", # 76
            "#006eff", # 77
            "#0069ff", # 78
            "#0064ff", # 79
            "#005fff", # 80
            "#005bff", # 81
            "#0056ff", # 82
            "#0051ff", # 83
            "#004cff", # 84
            "#0048ff", # 85
            "#0043ff", # 86
            "#003eff", # 87
            "#0039ff", # 88
            "#0035ff", # 89
            "#0030ff", # 90
            "#002bff", # 91
            "#0026ff", # 92
            "#0022ff", # 93
            "#001dff", # 94
            "#0018ff", # 95
            "#0013ff", # 96
            "#000fff", # 97
            "#000aff", # 98
            "#0005ff", # 99
            "#0000ff"] # 100
I love flight simming, coding, and writing in that order.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Assigning hex values from array to character.

#2 Post by hell_oh_world »

What you want is to make the character object dynamic...
I would suggest defaulting the character object and passing the static properties.

Code: Select all

default player = Character ("[sName]") # plain definition, dont define the dynamic properties yet.
then in your labels, once the the alignment variable is defined you need to reassign this character object again.

Code: Select all

label start:
  $ align = 0
  $ player = player.copy(who_color=alignColors[align]) # no need to interpolate your alignColors is already a list of string

User avatar
jpalmer999
Newbie
Posts: 6
Joined: Wed Aug 04, 2021 1:40 pm
itch: jonathanpalmer
Contact:

Re: Assigning hex values from array to character.

#3 Post by jpalmer999 »

Thanks this worked perfectly. Also where's your avatar from? Looks pretty cool.
I love flight simming, coding, and writing in that order.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Assigning hex values from array to character.

#4 Post by hell_oh_world »

jpalmer999 wrote: Fri Aug 06, 2021 6:29 am Thanks this worked perfectly. Also where's your avatar from? Looks pretty cool.
It's from Dota 2's Wraith King's Arcana actually...

Post Reply

Who is online

Users browsing this forum: Bing [Bot]