Discord
Login
Community
DARK THEME

return true If a variable has changed

basically want a function to return true if a variables value has changed and I dont really know where to start


Variable = class
  constructor = function( v )
    this.value = 0
    this.changed = false
    this.setValue( v )
  end
  
  setValue = function( v )
    if this.value != v then 
      this.value = v
      this.changed = true
    else 
      this.changed = false
    end
  end
  
  getValue = function()
    return this.value
  end
  
  resetChanged = function()
    this.changed = false
  end
end


init = function()
  virable = new Variable( 5 )
  print( "value = " + virable.value + " changed = " + virable.changed )
  virable.setValue( 5 )
  print( "value = " + virable.value + " changed = " + virable.changed )
  virable.setValue( 10 )
  print( "value = " + virable.value + " changed = " + virable.changed )
  virable.resetChanged()
  print( "value = " + virable.value + " changed = " + virable.changed )
  
end

Thanks, :)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community