Is there a better way to write this line?

This line of code feels very redundant and inefficient. Is there a better way to do this?

local favorability_variable1, favorability_variable2, favorability_variable3, favorability_variable4 = STARTING_FAVORABILITY,STARTING_FAVORABILITY,STARTING_FAVORABILITY,STARTING_FAVORABILITY`

I could do it this way but it kinda wastes 4 lines in my opinion.

local favorability_variable1 = STARTING_FAVORABILITY
local favorability_variable2 = STARTING_FAVORABILITY
local favorability_variable3 = STARTING_FAVORABILITY
local favorability_variable4 = STARTING_FAVORABILITY
1 Like
-- Shorten the name
local Favor_1 = STARTING_FAVORABILITY
local Favor_2 = STARTING_FAVORABILITY
local Favor_3 = STARTING_FAVORABILITY
local Favor_4 = STARTING_FAVORABILITY
-- Use an array
local Favorabilities = {
  --[[1]] STARTING_FAVORABILITY, 
  --[[2]] STARTING_FAVORABILITY, 
  --[[3]] STARTING_FAVORABILITY, 
  --[[4]] STARTING_FAVORABILITY
}

real question would be: Do you actually need to define 4 seperate favorabilities?

7 Likes

or use a dictionary too

local Favorabilities={
 Favor_1=STARTING_FAVORABILITY, --["Favor_1"]
 Favor_2=STARTING_FAVORABILITY, --["Favor_2"]
 Favor_3=STARTING_FAVORABILITY, --["Favor_3"]
 Favor_4=STARTING_FAVORABILITY, --["Favor_4"]
}
2 Likes

it would be better to use an array in this case since all that did was make the index longer

Favorabilities.Favor_1

...

Favorabilities[1]
print(#Favorabilities)
2 Likes

spetially because you used numerical index

1 Like

Definitely a sign to look over my code again :joy:

I was really just curious to see if there was a better way to define variables with the same value. Your reply was helpful though, an array is a good idea.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.