Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Iridium Banner AMIStore App Store A1200/A600 4xIDE Interface

AuthorTopic: Parameters in RequestChoice / RequestFile commands  (Read 352 times)

0 Members and 1 Guest are viewing this topic.

Offline AndyFC

Parameters in RequestChoice / RequestFile commands
« on: November 20, 2020, 09:10:39 PM »
Evening all.

I'd like to display a parameter captured in a script using the Requestfile command to be displayed in the RequestChoice prompt. I've tried a few different things but the name of the parameter is displayed in some form and not the value of the parameter (in this case a file path).

Is what I'm trying to do possible and, if so, how please?

I guess the fallback is a Shell output Window.

Thanks.
A1200 in DIY Tower. 3.0 ROMS (but 3.1 in RAM), 3.5" HD, CD Rom and IDE to SD adapter running off the internal IDE port (using the A4000 4-port IDE adapter from Amigakit), Blizzard 1230-IV, with 32MB 60ns RAM and 50MHz 68882 FPU. 3COM PCMCIA Network card running with Miami DX. https://www.youtube.com/watch?v=1PrGdL6XjmE
 

Online TribbleSmasher

Re: Parameters in RequestChoice / RequestFile commands
« Reply #1 on: November 20, 2020, 10:11:28 PM »
I don't know if this works prior to 3.1.x but this works here:

You set or get the value or string you want to display with e.g. Env variables. To insert them you can use backticks.
Edit:
using backticks (3.0+ i think)
Code: [Select]
LIST `REQUESTFILE DRAWERSONLY'

Example 1
Code: [Select]
SETENV myval "important"

REQUESTCHOICE TITLE "hello user" BODY `GETENV myval` OkeyDokey
Example 2
You can also use a script as a body for the requester( the variable acts as a script).
Edit: ok, maybe not full scripts, but internal cmds, like ECHO, EVAL etc.
Code: [Select]
SETENV myval "ECHO 42"

REQUESTCHOICE TITLE "hello user" BODY `$myval` OkeyDokey
Hint
Code: [Select]
SETENV F 5
SETENV S 6
EVAL $F+$S
EVAL $F*$S
Example 3
And, finally, if you shape your myval with additional words separated with spaces, those become gadgets as well
Code: [Select]
SETENV myval "important Okey"

REQUESTCHOICE TITLE "hello user" BODY `GETENV myval` Dokey

As you already 'captured' your variable, just insert that instead.
Or, as Example 4
Code: [Select]
C:DATE >ENV:myval

REQUESTCHOICE TITLE "hello user" BODY "`GETENV myval`" "Okey Dokey!"
As Date outputs a string with spaces you certainly like to surround it with " ".
« Last Edit: November 21, 2020, 12:44:08 AM by TribbleSmasher »
 

Offline AndyFC

Re: Parameters in RequestChoice / RequestFile commands
« Reply #2 on: November 21, 2020, 09:14:03 PM »
Thanks TribbleSmasher.

This helped me get further (OS 3.1) but have found some limitations.

1: I want to show 2 parameters in the requester body. The first displays OK but the second shows the text 'Getenv' and whatever the variable name is. I've got around this by combing two variables into a new, single, variable which leads to problem 2...

2: The data I want to display is a file path and if it has a space in the value gets automatically wrapped in double quotes. Even though they aren't displayed on screen if you use GETENV they are there and the Requestchoice command sees it as the end of the <BODY>.

I'm nearly there. I've got the script to do what I want but have to reply on ECHO and a Shell Window for some of the output so this is purely an aesthetic issue now.
A1200 in DIY Tower. 3.0 ROMS (but 3.1 in RAM), 3.5" HD, CD Rom and IDE to SD adapter running off the internal IDE port (using the A4000 4-port IDE adapter from Amigakit), Blizzard 1230-IV, with 32MB 60ns RAM and 50MHz 68882 FPU. 3COM PCMCIA Network card running with Miami DX. https://www.youtube.com/watch?v=1PrGdL6XjmE
 

Online TribbleSmasher

Re: Parameters in RequestChoice / RequestFile commands
« Reply #3 on: November 21, 2020, 09:36:07 PM »
I don't really understand the problem.
Everything in backticks gets parsed the same way, so you could chain a list of commands together.
Inserting *N provides a linefeed in the body.
Code: [Select]
setenv myval1 "drive:Internet Apps/"
setenv myval2 "42"

requestchoice TITLE "hello" BODY "`GETENV myval1`*N`GETENV myval2`" "Okey"

Note:
Once any *N is found it is replaced with a linefeed, so you cannot use ECHO *N (to create a single linefeed) as it would end the current line and therefore the command issued. You need to create the lines separately and later join them together.
ECHO without the NOLINE parameter also issues a linefeed.
Also, when the RequestFile returns a string with surrounding "" you send this to a variable and once it get parsed the "" got stripped.
« Last Edit: November 21, 2020, 10:21:09 PM by TribbleSmasher »
 

Offline kolla

Re: Parameters in RequestChoice / RequestFile commands
« Reply #4 on: November 21, 2020, 10:46:51 PM »
Why system wide setenv and not just shell local set?

Why backtick getenv var instead of just using ${var}?
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM460 and Mac minis with MorphOS
 

Online TribbleSmasher

Re: Parameters in RequestChoice / RequestFile commands
« Reply #5 on: November 22, 2020, 08:36:12 AM »
because i don't know better. :)
You had every chance to chip in for a long time to provide help. :)
 

Offline kolla

Re: Parameters in RequestChoice / RequestFile commands
« Reply #6 on: November 22, 2020, 06:14:29 PM »
because i don't know better. :)

But you’re using $var with eval, so I’m confused about what you know or not :)

Setenv/getenv is for system global variables, and these are saved as files in ENV: and you can make them survive boots by also saving them in ENVARC:

Set/get are for shell local variables, they are only accessible from within the shell they were made.

In general it is advisable to use local variables in scripts - if you use global variables, you risk that scripts stumble in its other’s feet as they potentially share variables... for example if same script is running twice, at once.

And local shell variables overrides global variables.

When referring to variables in the shell or shell scrips, you use dollar sign in front of the variable name - for example $var, so no need for backticking getenv or get.

But it is good practice to use curly brackets around variable names, as that allows you to have special signs in them, for example global variables may have / in their names, when stored in a directory in ENV: - for example ${bla/myvar} which refers to the content of file env:bla/myvar


Sadly, even latest 3.1.4.1 RequestChoice is rather braindead and doesn’t automatically wrap lines that are long, so you can easily make requesters that would be wider than the screen, if that was possible, so the requester is typically “cut” at screen width, and if there’s only one button, it may very well be hidden “outside” of the screen, unreachable by pointer. In his infinite wisdom, the chief OS developer decided that no window is allowed to be wiser than screen to prevent exactly this thing from happening, yet here we are... and if a requester was allowed to actually be wider than screen, you could have dragged and pulled it to the left till button was reachable, but we cannot have that, because... Microsoft Windows!! *spit pfffeh* Luckily there is a way out from this “bug” if you get there, and that is to use left-amiga + v or left-amiga + b, the former being equivalent to pressing leftmost button (typical “ok”), and the latter equivalent to rightmost button (typical “cancel”) and if only one button.. act as if there was an invisible cancel there.

So yeah, instead of having automatic flow, we must use *N and create newlines ourselves... and we are also stuck with “system screen font” for requester body. And you cannot select and copy from requester. And... and... meh.
« Last Edit: November 22, 2020, 06:29:59 PM by kolla »
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM460 and Mac minis with MorphOS
 

Online TribbleSmasher

Re: Parameters in RequestChoice / RequestFile commands
« Reply #7 on: November 22, 2020, 07:30:19 PM »
Thanx for the insight. As i don't know the OPs initial use case i just tried to give possible ways to go. Maybe there is a demand for a new DOS manual after all which could include those advanced scripting lessons.
« Last Edit: November 22, 2020, 07:31:36 PM by TribbleSmasher »
 

Offline AndyFC

Re: Parameters in RequestChoice / RequestFile commands
« Reply #8 on: November 23, 2020, 07:32:12 PM »
Thanks again for the advice. I'm thinking this might be a limitation of 3.0 and/or 3.1 because I get a different result to TribbleSmasher with a similar script.

The top box is my text script. I'm echoing the variables to debug them and the second window is the output demonstrating that I'm setting the values correctly.
The third window is the RequestChoice box showing the first value displaying correctly but the second isn't, being replaced by the command.

I've tried a few different combinations including $ variables, SETENV and GETENV, backticks and {} but still don't get the desired output in the RequestChoice box.
A1200 in DIY Tower. 3.0 ROMS (but 3.1 in RAM), 3.5" HD, CD Rom and IDE to SD adapter running off the internal IDE port (using the A4000 4-port IDE adapter from Amigakit), Blizzard 1230-IV, with 32MB 60ns RAM and 50MHz 68882 FPU. 3COM PCMCIA Network card running with Miami DX. https://www.youtube.com/watch?v=1PrGdL6XjmE
 

Offline nbache

Re: Parameters in RequestChoice / RequestFile commands
« Reply #9 on: November 23, 2020, 10:10:05 PM »
The following works for me in 4.1.

Code: [Select]
Set Infile `Requestfile TITLE "Input"`
Set Outfile `Requestfile TITLE "Output"`
Set Confirm `RequestChoice TITLE "Confirm" Body "$Infile*n$Outfile" "Quit"`
Echo $Confirm

(The last line is just to verify the RequestChoice worked as expected.)

I would expect that it would also work in 3.x, but of course I can't guarantee it.

Still, maybe it can inspire some new attempts.

Best regards,

Niels
 

Offline kolla

Re: Parameters in RequestChoice / RequestFile commands
« Reply #10 on: November 24, 2020, 10:25:55 PM »
@nbache

Thank you for bringing some sanity to this madness :)
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM460 and Mac minis with MorphOS
 

Offline nbache

Re: Parameters in RequestChoice / RequestFile commands
« Reply #11 on: November 24, 2020, 11:26:05 PM »
My pleasure :-)

BTW, there may still be some precautions to take if the file/path happens to contain spaces or other annoying stuff - I didn't test that.

(This is where I'm supposed to say "left as an exercise for the reader ;-)).

Best regards,

Niels
 

Offline AndyFC

Re: Parameters in RequestChoice / RequestFile commands
« Reply #12 on: November 25, 2020, 01:23:03 PM »
I've had a chance to try Neils' suggestion, using 'Set' at the beginning of the RequestChoice line and this works. There are some caveats:
- Like he warns, having a space in the path ("Ram Disk:" was one of my paths) causes an error. This is strange because setting the parameter as I did originally doesn't produce the same error.
- The 'cause' of the original question where I can't display the second parameter in RequestChoice is because of the waay I call the parameter in the RequestFile command. Using "Requestfile >Env:(parametername)...etc" results in me not being able to show a second parameter in the RequestChoice command. This is the case even if the parameter being called in RequestFile isn't used in RequestChoice

e.g.
Code: [Select]
Set Value1 `Requestfile >Env:Value2 TITLE "Hello"
Set Value3 `Requestfile >Env:Value4 TITLE "World"
RequestChoice TITLE "Test" BODY"$Value1*N$Value3" "Quit"

Results in the parameter $Value3 not getting displayed correctly in the choice requester but:

Code: [Select]
Set Value1 `Requestfile TITLE "Hello"
Set Value3 `Requestfile TITLE "World"
RequestChoice TITLE "Test" BODY"$Value1*N$Value3" "Quit"

works.

Thanks for all your help nbache, TribbleSmasher and Kolla. I've learn a lot about different variables and how to set and retrieve them through this task. I've got a plan of how to deal with the spaces in the path.
A1200 in DIY Tower. 3.0 ROMS (but 3.1 in RAM), 3.5" HD, CD Rom and IDE to SD adapter running off the internal IDE port (using the A4000 4-port IDE adapter from Amigakit), Blizzard 1230-IV, with 32MB 60ns RAM and 50MHz 68882 FPU. 3COM PCMCIA Network card running with Miami DX. https://www.youtube.com/watch?v=1PrGdL6XjmE
 

Offline nbache

Re: Parameters in RequestChoice / RequestFile commands
« Reply #13 on: November 25, 2020, 04:18:15 PM »
@AndyFC:

Quote
I've got a plan of how to deal with the spaces in the path.
*SPOILER ALERT*

Just in case you haven't found a good way yet (or someone else wants a solution):

Code: [Select]
Set Infile `Requestfile TITLE "Input"`
Set Outfile `Requestfile TITLE "Output"`
Set Confirm `RequestChoice TITLE "Confirm" Body "*"$Infile*"*n*"$Outfile*"" "Quit"`
Echo $Confirm

Edit: Hmm ... under 4.1, paths with spaces actually work already without that modification. Under 3.x, YMMV.

Best regards,

Niels
« Last Edit: November 25, 2020, 04:26:44 PM by nbache »