Jump to content
UBot Underground

Monitor Variable, Perform Action


Recommended Posts

Hi

 

Do you guys have an idea about how to monitor a variable and if it has a value, then perform an action?

This is my current if statement:

if($comparison(#FileChooser0,"!=",$nothing)) {
    then {
        ImportCSV()
        comment("Clear the variable")
        set(#FileChooser0,$nothing,"Global")
    }
}

It works fine if I run it manually, but the point is, I want to load a file into the system without having to press a button after the file is selected. A constant loop seems like a bad idea for performance... 

Link to post
Share on other sites

Not Sure Try.

define ImportCsv(#FileIn) {
    if($file exists(#FileIn)) {
        then {
        }
        else {
        }
    }
}

 

Link to post
Share on other sites

Hi pash

 

Thanks for the suggestion, but from what I understand, a define only runs when it's called? Anyway, I tried it, but no luck.

What I did:

define ImportCheck(#FileChooser0) {
    if($file exists(#FileChooser0)) {
        then {
            ImportCSV()
            comment("Clear the variable")
            set(#FileChooser0,$nothing,"Global")
        }
    }
}
Link to post
Share on other sites

Dyvel, I think the only way to achieve that is to run an extra thread that would be checking that variable value and execute some code if needed.

 

UBot and neither any of the plugins (as far as I know) support events and triggers.

Link to post
Share on other sites
  • 3 weeks later...

so when the file is not their,the bot is idle?

even asynchronous file reading must loop(I think lol)

 

ui open file("open file",#file open)

define $file added(#file added) {
    alert("File added!")
    set(#file open,"","Global")
    set(#back to sleep,    $file wait(""),"Global")
}
define $file wait(#file wait) {
    if($comparison(#file open,"=",$nothing)) {
        then {
            wait(0.5)
            set(#back to sleep,            $file wait(""),"Global")
        }
        else {
            set(#do something,            $file added(""),"Global")
        }
    }
}
set(#start,$file wait(""),"Global")

 

I dont know how but this works as asynchronous(i think thats what it is called,forgive me for not understanding the concept properly :) ) code,I can keep building other nodes and this is still working away even after pressing stop lol

 

Anyone know why!! awesome ha ha

  • Like 1
Link to post
Share on other sites

Hi

 

maybe this can help u

ui html panel("<html><head>
<meta charset=\"utf-8\">
   <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js\"></script>
   <script>
$(function()\{
    $(\'#myvar\').on(\'change\', function()\{

      // only one Time Dom-Search
      var m = $(\'#myvar\');

      // look if the inputfield is not empty
      if(m.val() != \"\")\{

      //console.log(\'works\');
      // starts the define with your jobs
      ubot.runScript(\'do_the_job()\');
      // set the input back to empty
      m.val(\"\");
      \}

    \});
\});
   </script>

  </head>
  <body>

  <input type=\"text\" id=\"myvar\">

  </body>

  <html>", 100)
define do_the_job {
    alert("works!")
}

blumi

  • Like 2
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...