Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:52:39+00:00 2026-06-09T14:52:39+00:00

Is it possible to detect when the value of a variable has changed using

  • 0

Is it possible to detect when the value of a variable has changed using the lua debug library.
Something like A callback function which would give details like the function in which the value was changed, previous value, etc.
Is such a thing possible?

I read about hooks, but I’m not sure hooks can be set to variables.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:52:40+00:00Added an answer on June 9, 2026 at 2:52 pm

    If you don’t mind using a debugger, then some debuggers allow you to set Watch expressions, which will be triggered when the condition in the expression is true. I’ll show how this can be done in MobDebug (it is using lua debug library, but there is no direct way to detect a variable change as far as I know).

    Let say we have a script start.lua like the one below and want to detect where foo gets value 2:

    print("Start")
    local foo = 0
    for i = 1, 3 do
      local function bar()
        print("In bar")
      end
      foo = i
      print("Loop")
      bar()
    end
    print("End")
    
    1. Download mobdebug.lua and make it available to your scripts (the simplest way is to put it into the folder with your scripts).
    2. Start the server using lua -e "require('mobdebug').listen()" command.
    3. Start the client using lua -e "require('mobdebug').loop()" command.
    4. You will see the prompt in the server window: ‘>’. Type load start.lua to load the script.
    5. Type step and then step again. You will see “Paused at file start.lua line 3”.
    6. Let’s see what the value of foo is. Type eval foo and you should see 0.
    7. Now we can set up our watch. Type setw foo == 2. You can specify any Lua expression after setw command; the execution of your script will be stopped when the condition is evaluated as true.
    8. Continue execution of the script using “run” command.
    9. The watch now fires, which will show you the message like: “Paused at file start.lua line 8 (watch expression 1: [foo == 2])”. This means that the previous expression changed the value of foo to 2 and the execution is stopped at line 8. You can then inspect your script and the current values (you can use “eval” and “exec” commands to run any Lua code to be evaluated in your script environment) to find what triggered the change.

    The benefit of this approach is that you are not limited to monitoring table values and can specify any expression. The main disadvantage is that your script runs under a debugger and the expression is evaluated after each step, which may get really slow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to detect the specific webcam hardware that a person is using
Is it possible to detect that the user has an external headset plugged into
is it possible to detect if flash is installed using PHP. My aim is,
I want to detect existence of a specific member function for a class, using
Is it possible to execute a function , then return a new value for
Using Php is it possible to detect exact OS even if the browser agent
Is it possible to use EventListener to Listen to a variable and detect when
I want to know if it's possible to detect available colors in terminal which
Is it possible to detect a route value in a view? Such as /pages/create/1
I'd like to know if it's possible to determine what inline styling has been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.