English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 09 October 2021, 00:29   #1
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Lightbulb AmigaOS 1.3 'askL' & 'askM' commands

Now that I found a way to use variable(s) inside a script, the next step was to find a way to get some "real" input from the user by allowing him/her to type an answer (like asking the source/destination/a name/etc. - and not only a yes/no tests as with the original 'ask' command).

Honestly speaking, it was not a "keep it easy" task and it shook my mind in a lot of directions.

Finally I came across a solution (my install is a WB 1.3.3 - other versions not tested). It is maybe not the most 'clean' idea but it does the job so ...

The working solution requires to create two scripts. The "main" script (I called it AskL for "ask long") that the user execute and another script, a "stealth"* one (AskL2) that is called by the first one to 'do the job' of retrieving the user input and storing the variable.
*see StingRay post #2

The 'command' ends when an answer is provided (otherwise it keeps asking).

Here are the codes :
Code:
AskL :
.key question
.bra {
.ket }
.def question "? "
lab mlk ;(see below)
echo "{question}" NOLINE
execute >NIL: AskL2 reponse ? ;>NIL: to switch the execute to 'non visible' 
                              ;      mode (stealth)
                              ;'?'   to force the 'template' mode (like when 
                              ;      you don't remember the arguments/options 
                              ;      of a command) and since it is invisible, we 
                              ;      don't see we have switched to another 
                              ;      command :p
if EXISTS t:repondu
   delete t:repondu QUIET
else
   ;skip mlk BACK ;not working. As I can see, the above 'execute' makes that
                  ;the script looses the labels he knows... Grrrr... :(
   execute AskL "{question}"
endif
Code:
AskL2 :
.key variable,a7_,b7_,c7_,d7_,e7_,f7_,g7_,h7_,i7_,j7_,k7_,l7_,m7_,n7_,o7_,p7_,q7_,r7_,s7_,t7_,u7_,v7_,w7_,x7_,y7_,z7_  ;adapt the amount of needed arguments (c.f. below)
.bra {
.ket }
;warning: At prompt, do not type the same value as the name of one of the
;         argument. It will hang the execute command and thus also the script.
if "{a7_}" EQ ""
   if EXISTS t:repondu
      delete t:repondu QUIET
   endif
else
   setenv {variable} "{a7_} {b7_} {c7_} {d7_} {e7_} {f7_} {g7_} {h7_} {i7_} {j7_} {k7_} {l7_} {m7_} {n7_} {o7_} {p7_} {q7_} {r7_} {s7_} {t7_} {u7_} {v7_} {w7_} {x7_} {y7_} {z7_}"  ;adapt to your needs (c.f. above)
   echo >t:repondu "" NOLINE
endif
Don't forget to
Code:
protect AskL +s
and now you can simply type
Code:
AskL
or
AskL "question ? "
Then the provided answer is available through the 'getenv' command
Code:
getenv reponse
and it can be used as described here : https://eab.abime.net/showthread.php...27#post1510227

Any comment is welcome.

Last edited by malko; 11 October 2021 at 00:27.
malko is offline  
Old 10 October 2021, 01:31   #2
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Lightbulb for WB 34.(21|28|34)

I didn't mention it in my previous post but the AskL scripts accept answer from 1 word to up to 26 words separated by spaces (or more if you adapt the second script - but 26 words is already a long phrase and thus is more than enough I think).

A much simpler solution, made of only 1 script, would consist of accepting a only 1 word answer OR require the user to put in quotes multiple words answer :

Code:
AskM :
.key question
.bra {
.ket }
.def question "? "
lab mlk
echo "{question}" NOLINE
failat 21
setenv >NIL: reponse ?   ;see 'AskL' for the comments regarding '>NIL:' & '?'
if ERROR
   skip mlk BACK
endif
if "$reponse" EQ ""
   skip mlk BACK
endif
As previously the provided answer is available through the 'getenv' command
Code:
getenv reponse
and it can be used as described here : https://eab.abime.net/showthread.php...27#post1510227

Last edited by malko; 11 October 2021 at 00:28.
malko is offline  
Old 11 October 2021, 00:50   #3
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Quickly tested the scripts AskL/AskL2 & AskM under WB 1.3.2 (34.28), 1.3 (34.21). They are also working fine.

In the other hand, WB 1.2 (33.56), 1.1 (31.334) and 1.0 (30), have no 'setenv', 'getenv' commands. Neither have them the NOLINE argument for the 'echo' command or the T: and ENV: by default. Therefore the scripts won't work as is.
malko is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
XAD commands npagonis73 support.Other 29 17 March 2022 15:15
AmigaOS 1.3 'tstdvc' , 'ctrflp' & 'ctrflpq' commands malko Coders. Scripting 0 29 October 2021 01:30
uae-configuration commands markpage support.WinUAE 18 02 May 2021 00:24
E-UAE for AmigaOS 4.1 help for commands White support.OtherUAE 0 16 February 2018 15:55
Zip help commands mickolite support.Apps 5 16 June 2011 21:00

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:35.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09927 seconds with 13 queries