How to use values in the same dictionary?

Is it possible to use values from a dictionary in the same one? I have provided an example below:

local events = {
    Event1 = {
	    Amount = math.random(10, 25),
	    Status = 'A random plate will stretch upwards by '..events.Event1.Amount..' studs', -- the line outputting the error
	    Event = function(plate)
	    	ts:Create(plate, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = Vector3.new(plate.Size.X, plate.Size.Y + 20, plate.Size.Z)}):Play()
	    end
    }
}

Could explain further what you mean by “use values from a dictionary in the same one”?

Using the values in the dictionary for other values.

Amount = math.random(10, 25),
Status = 'A random plate will stretch upwards by '..events.Event1.Amount..' studs', -- the line outputting the error

I’m trying to use the Amount key in a different one, but it does not work.

Your example should work. Have you tested your theory?

Yes, but it does not work:image

Is events Defined? I cannot tell since you are only providing a snippet of your code.

I forgot to include events in the post, apologies:

local events = {
    Event1 = {
	    Amount = math.random(10, 25),
	    Status = 'A random plate will stretch upwards by '..events.Event1.Amount..' studs', -- the line outputting the error
	    Event = function(plate)
	    	ts:Create(plate, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = Vector3.new(plate.Size.X, plate.Size.Y + 20, plate.Size.Z)}):Play()
	    end
    }
}

No, that won’t work. The script won’t know what the table is because it hasn’t been fully defined yet. You could do this though:

local events = {
   Event1 = {
	   Amount = math.random(10, 25),
	   Status = '', 
	   Event = function(plate)
		  ts:Create(plate, TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Size = Vector3.new(plate.Size.X, plate.Size.Y + 20, plate.Size.Z)}):Play()
	   end,

      SetStatus = function(self, int)
          self.Status = string.format("A random plate will stretch upwards by %d studs", int)
      end
    }
}

events.Event1:SetStatus(events.Event1.Amount) -- sets the status
1 Like