How would I run a function if two players have correlating variables?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Basically, I’m creating a combat system similar to Omori, where certain emotions can affect your damage. The best idea I’ve had was to store two tables. A table on top to represent the emotions that beat the emotions on the table below it.
    Example:
    image_2021-07-10_050420
    Basically, if one player has the Angry emotion currently on them, and the other player were to have the Happy emotion, then a function would run because those two emotions correlate in the tables.
  2. What is the issue? Include screenshots / videos if possible!
    I’m having a hard time trying to write this into code form
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking around but I had trouble searching because of how I’m struggling to phrase this question.

I don’t quite understand? Please give another example.

Sorry I’m not very good at explaining.


Hope this helps because I honestly can’t think of any other way to write this

I still don’t get it. Do you want a function to run both of these emotions?

You could utilize table.find() and check if both player’s emotions are in one of the tables. If not, then it’s safe to assume the other player’s emotion is in the other table. Presuming emotions always has a value from the tables.

For example,

if (table.find(StrongAgainst, Player1.Emotion) ~= nil and table.find(StrongAgainst, Player2.Emotion) ~= nil) then
    -- Whatever code you want to run if their emotions are in the same table.
else
    -- Different emotions code.
end
1 Like

I would index them, like this:

if Player1.Emotion == StrongAgainst[1] and Player2.Emotion == WeakAgainst[1] then
   -- code
end

i have made a script through what i understood:

local stronk = {"angery","hapy","sad")
local  weak = {"hapy","sad","angery")
local tableCount = 3 ----how much stuff is in table or you could use #weak to get how much stuff is in the table

function checkIfColaterate(Player1,Player2)
     for i,tableCount,1 do
      if stronk[i] == Player1.Emotion and weak[i] == Player2.Emotion then
           ----checking if indexing 1 in the table is equal to player 1 emotion and player 2 then it continues the script else it will index 2 in the table and check if its player 1 emotion etc..
      elseif weak[i] == Player1.Emotion and stronk[i] == Player2.Emotion  then
             ---if its the opposite in case of
          end
     end

end

Ah thanks so much I’m not good at explaining so I’m surprised you were able to do exactly what I was trying to accomplish

1 Like