james8tg
|
  |
| Joined: 25 Mar 2010 |
| Total Posts: 229 |
|
|
| 25 Jul 2017 02:57 AM |
Just a quick question,
I have an array setup with four values inside - say I wanted to change the value of Array[3], how would this be achieved?
Thanks, James |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 25 Jul 2017 03:56 AM |
local Array = {"value", "not a value", "property", "you went too far"}
local value_that_we_think_is_at_the_third_index = nil local edit_value_at_third_index_in_Array = nil
edit_value_at_third_index_in_Array = function(new_value) for k,v in pairs(Array) do if k > 0 and k == 3 and k % 3 == 0 and k <= #Array then if v ~= nil and v == v and v then if value_that_we_think_is_at_the_third_index == nil then value_that_we_think_is_at_the_third_index = v edit_value_at_third_index_in_Array(new_value) else if value_that_we_think_is_at_the_third_index == v then if not false then if new_value ~= value_that_we_think_is_at_the_third_index then Array[3] = new_value print("The value at the third index of the Array is now: "..tostring(new_value)) else error("Attempted to set the third index to the same value. Value not changed.") end end end end end end end end edit_value_at_third_index_in_Array("new property") |
|
|
| Report Abuse |
|
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
| |
|
| |
|
DevJoas
|
  |
| Joined: 17 Dec 2014 |
| Total Posts: 627 |
|
|
| 27 Jul 2017 05:57 AM |
@amanda
That's probably the best script I've ever seen :O |
|
|
| Report Abuse |
|
|