Page 1 of 1

Uservariable Delete

Posted: Thursday 04 August 2016 12:59
by jjdom
Hello everyone

I want to delete a UserVariable
So I'll use the appropriate Json query.

But this query needs the Idx of UserVariable.

This variable was created with a lua script. So if another script wants to delete it, does not know its id. He only knows his name.

How can I get this Idx with his name?

Re: Uservariable Delete

Posted: Thursday 04 August 2016 16:00
by Egregius
json.htm?type=command&param=getuservariables gives all variables
json.htm?type=command&param=deleteuservariable&idx=1 deletes the first

So, grab all variables, run thru the array and find the idx.

Re: Uservariable Delete

Posted: Thursday 04 August 2016 20:59
by jjdom
Thanks for you help Egregius

But how to get the result of the json query, and how to grab it ?

Re: Uservariable Delete

Posted: Friday 05 August 2016 6:50
by Egregius

Code: Select all

<?php
define('api',"http://127.0.0.1:8084/");
//Grab the variables
$variables = json_decode(curl(api."json.htm?type=command&param=getuservariables"),true);
//Check if the result isn't empty
if(!empty($variables['result'])){
    //loop thru all variables
    foreach($variables['result'] as $variable){
        //if variable value equals ... remove it.
        if($variable['Value']=="first") curl(api."json.htm?type=command&param=deleteuservariable&idx=".$variable['idx']);
    }
}
function curl($url){$headers=array('Content-Type: application/json',);$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);$data=curl_exec($ch);curl_close($ch);return $data;}

Re: Uservariable Delete

Posted: Friday 05 August 2016 13:16
by jjdom
Hello, Thanks for your answer,

But, I do not work in PHP, I work in LUA.
Have you a grab example in LUA?

Re: Uservariable Delete

Posted: Friday 05 August 2016 13:19
by Egregius
Nope :P