Learning to script!

Discuss and share scripts and script files...
Post Reply
sl23
Posts: 223
Joined: 03 Feb 2015 23:34

Learning to script!

Post by sl23 »

I'm having issues creating a simple button to create a new INI file. In fact, that's not strictly correct. I copied the script from the Help file: new("file.txt"); but wish to add the "r" flag to it. I don't understand why simply adding this breaks the code.

I've tried many variations but can't understand how to use it. There are no explanations in the "New" section of the Help file on it's usage.
My current script for this button is this: new("New INI File.ini", "type=file", , "r");
Do I need the "type=file", term?

I noticed there are some code snippets with two commas:
new(, , "<curitem>", "r"); are these placeholders for unused terms?

Is the semi-colon required at the end of this script/all scripts?

Also, this is massively confusing when starting out: new(name, [type=file|dir|link|symlink|hardlink|junction], [source], [flags])
It made me think that these terms needed to be in square brackets, but in fact they have to be in quotes! Why in a help file would they be shown this way? Makes no sense. I only figured it out by looking at examples further down and trial and error, not really how it should be done.

I'm also confused why this button works, without the "r", but when I add the same code to the Menu button on the Breadcrumb bar, it doen't work. Does this menu require more code in order to operate as a toolbar button would?

Thanks for any help you can offer.

To highend - This is what I meant previously with Help files, they can be useful when you know how to script, but for complete beginners, they are never a useful learning tool. Hence why I didn't use it at the start. Though I have to admit, it is very comprehensive and has at least got me started, just! :biggrin:
As with Rainmeter, I learnt more by using others code than the manual/help files. But scripting is way different from the simple code in Rainmeter! For a start, there are many different styles it seems, but maybe that's my lack of knowledge giving me that impression?

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Learning to script!

Post by highend »

Do I need the "type=file", term?
No. Why not? Because "file" is already the default. The help file entry for new mentions this.
Why doesn't it work? type is the name of the argument. You don't supply the name of an argument, but only it's value.
Like in every other programming language as well.

new("New INI File.ini", "file", , "r");
new("New INI File.ini", , , "r");

Are doing exactly the same.
are these placeholders for unused terms?
You need to supply all arguments to a command in XY that are not optional. Optional entries can be left out. Hence these empty entries.
Is the semi-colon required at the end of this script/all scripts?
Explained in the help file in the paragraph "General Command Syntax" under "Scripting".
It made me think that these terms needed to be in square brackets
Square brackets surrounding an argument for a function call = Argument is optional
Does this menu require more code in order to operate as a toolbar button would?
Because that's "Quick scripting" (explained in the help file) and needs a leading "::". Additionally that place uses the syntax of
popupmenu (also explained in the help file under "Breadcrumb Bars") which uses a caption|data|icon|state syntax.
In other words, this would have worked: ::New ini file;new("New INI File.ini", , , "r");

I've learned XY scripting by reading the help file (A LOT). So obviously that's possible...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

sl23
Posts: 223
Joined: 03 Feb 2015 23:34

Re: Learning to script!

Post by sl23 »

...
Last edited by sl23 on 16 May 2021 23:58, edited 1 time in total.

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Learning to script!

Post by highend »

But... I bet you knew about programming/scripting beforehand
I've learned AutoHotkey before. By using... the help file of it^^
EDIT: Forgot to ask, why the extra colon when used in the popup menu?
You obviously didn't read the help file entry for popupmenu()...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

sl23
Posts: 223
Joined: 03 Feb 2015 23:34

Re: Learning to script!

Post by sl23 »

...

Post Reply