Logic Machine Forum
Edit script but it still run old script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Edit script but it still run old script (/showthread.php?tid=5926)



Edit script but it still run old script - pouralise - 16.03.2025

I use a script 1/1/2 to update script of address 1/1/1 example from log(1) to log(2) using those commands:

Code:
        db:update('scripting', {script = nScript}, {id = s.id})
        script.disable(s.name)
      script.enable(s.name)
        script.reload()

The update is successful (I see the line log(2) in 1/1/1) but when I change the value of 1/1/1, it still run old script (show 1 in log instead of 2)
How can I fix this? Thank you


RE: Edit script but it still run old script - pouralise - 17.03.2025

Could someone help me please?


RE: Edit script but it still run old script - admin - 17.03.2025

Explain your use case. You should not need to update scripts dynamically.


RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 09:25)admin Wrote: Explain your use case. You should not need to update scripts dynamically.

I want my end-user can update the script without any coding skill. Like they can setup a script that turn on Light 1, wait 8 second then turn off Light 2, and they can edit it later when they need. They can do that with only tap/swipe item on visulization and the code will change depend on their action.


RE: Edit script but it still run old script - admin - 17.03.2025

Why not use scenes for this?


RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 09:36)admin Wrote: Why not use scenes for this?

Because I think write/read script is faster and more complex than edit/read scene. And sometime I need to check value of a specific address before taking the action. Example, if 1/1/1 = 10 and 1/1/2 = true I will do action A but when 1/1/1 = 10 and 1/1/2 = false I will do action B.


RE: Edit script but it still run old script - Daniel - 17.03.2025

Your client will use objects to insert the values so why do you need to modify the script?


RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 09:42)Daniel Wrote: Your client will use objects to insert the values so why do you need to modify the script?

It's not just about control the device. Example I creat some text Input in the Vis. And maybe they can add the option send email to "abc@gmail.com" with the subject "Something happen" which they can set themself when the object is set to specific value.


RE: Edit script but it still run old script - Daniel - 17.03.2025

String, number - no difference. You still must use a object where your user will type the values and your script will just read this.


RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 09:50)Daniel Wrote: String, number - no difference. You still must use a object where your user will type the values and your script will just read this.

Let say when they want to send the email to 100 user, if I use object or storage to store that value, it's not a wise idea. My Idea is I can use only one object.
Example
The script I want to edit is 1/0/1
1/7/1 will store the email address

When 1/0/1 = 1, they want to send email to "abc", they will set 1/7/1 to "abc", 1/0/1 will be set to 'email("abc")'
then they want to send to another email "abcd"  , they will set 1/7/1 to "abcd" , 1/0/1 will be set to 'email("abc") email(abcd)'
...


RE: Edit script but it still run old script - admin - 17.03.2025

Use this:
Code:
scriptid = 23
scriptcode = [[
log('1234')
]]

params = {
  data = {
    id = scriptid,
    scriptonly = true,
  },
  script = scriptcode
}

webrequest = require('webrequest')
res, err = webrequest('scripting', 'save', params)



RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 10:20)admin Wrote: Use this:
Code:
scriptid = 23
scriptcode = [[
log('1234')
]]

params = {
  data = {
    id = scriptid,
    scriptonly = true,
  },
  script = scriptcode
}

webrequest = require('webrequest')
res, err = webrequest('scripting', 'save', params)

Sadly it didnt work. I also try to run your whole code alone but it the script which has ID = 23 didnt change to log('1234')


RE: Edit script but it still run old script - admin - 17.03.2025

Anything in the error log? Which firmware version do you have?


RE: Edit script but it still run old script - pouralise - 17.03.2025

The log said: module 'webrequest' not found:. How can I install it?

I'm using 20210521 FWW


RE: Edit script but it still run old script - admin - 17.03.2025

Install 2024 firmware: https://openrb.com/firmwares/


RE: Edit script but it still run old script - pouralise - 17.03.2025

(17.03.2025, 13:27)admin Wrote: Install 2024 firmware: https://openrb.com/firmwares/

Is there any alternate way to do it with http request? I dig a bit and see that I can send http post to "/scada-main/scripting/save" with the payload contain data and script ID. But I dont know how to extractly do that in code. I try some code but get the response (404 Not Found)