One-Line Script Gives "Unk Stmt" Error - Script Writing - CHDK Forum

One-Line Script Gives "Unk Stmt" Error

  • 4 Replies
  • 6108 Views
One-Line Script Gives "Unk Stmt" Error
« on: 31 / July / 2018, 18:41:43 »
Advertisements
I have a one-line script to disable the USB Remote function...



@title AAUSB2PC
@chdk_version 1.3
set_config_value(121,0)


I get an Unk Stmt error, which I guess is unknown statement. I have no clue how such a simple script can fail to run. Even if the index number of the config value is wrong (I'm not sure 121 is for USB Remote), the script should run, correct?
I even tried replacing the "set_config" line with "sleep 250". Still fails. Adding "end" makes no difference.
There's gotta be a fundamental problem somewhere.


The script is saved as AAUSB2PC.bas.
I use Windows Notebook to create it, and save it with UTF-8 encoding, as the default ANSI encoding creates a parse error when I try to run it.
I am running CHDK 1.4. Can anyone point me in the right direction?


Thanks!

UPDATE:
I took one of the scripts that come with CHDK, hdr.bas, and ran it. It runs fine.
Then I opened it in Notepad, and saved it with a new name, using UTF-8 encoding. This new script fails with the same error.
I tried all 4 encoding options available in Notepad, they all fail.
I have no options left. Has anyone else had this happen?


Vinz
« Last Edit: 31 / July / 2018, 21:31:08 by VinzVideo »

*

Offline reyalp

  • ******
  • 14126
Re: One-Line Script Gives "Unk Stmt" Error
« Reply #1 on: 31 / July / 2018, 23:21:25 »
set_config_value(121,0)
is lua syntax, so you should name your file .lua, or use ubasic syntax.

Quote
I use Windows Notebook to create it, and save it with UTF-8 encoding, as the default ANSI encoding creates a parse error when I try to run it.
You must use ANSI, notepad puts a BOM at the start if you use UTF-8. The error you got the first time was likely due to the lua syntax in a .bas file.
Don't forget what the H stands for.

Re: One-Line Script Gives "Unk Stmt" Error
« Reply #2 on: 01 / August / 2018, 11:30:13 »
Yes, Reyalp, thank you.
Using debugger, I was able to see the BOM from encoding as UTF-8. So I went back to ANSI.
But I had no idea that the command I was using was LUA language.
I have it working now - thanks again.


v

*

Offline reyalp

  • ******
  • 14126
Re: One-Line Script Gives "Unk Stmt" Error
« Reply #3 on: 01 / August / 2018, 14:13:37 »
But I had no idea that the command I was using was LUA language.
I have it working now - thanks again.
Most commands exist in both (but there are exceptions, see https://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page)

In Lua, the parameters go in parentheses and have a comma in between like

Code: [Select]
foo(x,y)

In ubasic, the equivalent is usually
Code: [Select]
foo x, y

or maybe in some cases
Code: [Select]
foo x y
I don't actually remember whether ubasic accepts either or requires one way or the other depending on the command. I'd suggest sticking with Lua...
Don't forget what the H stands for.

Re: One-Line Script Gives "Unk Stmt" Error
« Reply #4 on: 01 / August / 2018, 15:13:38 »
Thanks again, Reyalp.


For what it's worth, I rewrote the script for uBasic, and changed it so the same script can either enable or disable the USB Remote. This is a lot easier than going into the CHDK menu system and scrolling, especially since my S100's are mounted vertically.
Here's the script I am now using...
The is_key "up" section is not necessary, it's just a quick way to exit without doing anything.


Code: [Select]

@title USB REMOTE OFF-ON
@chdk_version 1.3


:loop
wait_click
is_key k "left"
if k=1 then goto "usb_off"


is_key k "right"
if k=1 then goto "usb_on"


is_key k "up"
if k=1 then goto "finish"
goto "loop"


:usb_off
set_config_value 121 0
print "USB CONNECT TO PC"
end


:usb_on
set_config_value 121 1
print "USB REMOTE ENABLED"
end


:finish
end
« Last Edit: 01 / August / 2018, 15:16:18 by VinzVideo »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal