English Amiga Board


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

 
 
Thread Tools
Old 05 August 2015, 11:54   #1
liviux76
Registered User
 
liviux76's Avatar
 
Join Date: Jan 2014
Location: BO/Italy
Posts: 711
AmigaDos script help

Hello all!
Inspired by this thread where Retrofan adds a nice "tool" for RealAmikit users, I decided to create a small script to do the same (pick a game randomly and execute it through WHDLoad) for a "standard" Workbench.

Once obtained the list of my games (to be precise the list of my .slave files) and "formatted" it the way I needed (actually Retrofan did the difficult part ) I had to find some programs able to execute randomly a line from a file.

I found two programs that do this quiet efficiently: pickfile and randome .

So the script was quite easy (please, keep in mind that I am a beginner in AmigaDos scripting) and it works very well when launched from CLI:

Code:
; Play Random Game
.KEY PRG
IF NOT EXISTS RAM:prg.list
list Data:WHDLoad/#?/#?/#?.slave >RAM:prg.list lformat="cd *"%p*" && WHDLoad *"%n*" PRELOAD"
C:pickfile F=RAM:prg.list
;C:RandomE RAM:prg.list Times=1
ELSE
C:pickfile F=RAM:prg.list
;C:RandomE RAM:prg.list Times=1
ENDIF
It creates the file "prg.list" on my "RAM:" that contains a lot of lines as follows:

Code:
(...)
cd "Data:WHDLoad/R/RevengeOfDefender/" && WHDLoad "RevengeOfDefender.slave" PRELOAD
cd "Data:WHDLoad/R/RickDangerous2/" && WHDLoad "RickDangerous2.slave" PRELOAD
cd "Data:WHDLoad/R/RiseOfTheDragon/" && WHDLoad "RiseOfTheDragon.Slave" PRELOAD
cd "Data:WHDLoad/R/RiskyWoods/" && WHDLoad "RiskyWoods.Slave" PRELOAD
cd "Data:WHDLoad/R/Rockford/" && WHDLoad "Rockford.slave" PRELOAD
cd "Data:WHDLoad/R/RainbowWarrior/" && WHDLoad "RainbowWarrior.Slave" PRELOAD
cd "Data:WHDLoad/R/RickDangerous/" && WHDLoad "RickDangerous.Slave" PRELOAD
(...)
Then, either pickfile or randome executes a line randomly.

The problem arises when I want to execute this script from Workbench. I created a .info file for the script and modified it in order to execute the script with "C:IconX" but I always receive an error.

The creation of the list works well but when the script tries to execute a line it gives me the following errors:

Using randome
Code:
Error executing
cd "Data:WHDLoad/R/Rockford/" && WHDLoad "Rockford.slave" PRELOAD
Using pickfile
Code:
cd "Data:WHDLoad/R/Rockford/" && WHDLoad "Rockford.slave" PRELOAD
Wrong Number of Arguments
cd failed return code 20
It seems that those two programs cannot execute two commands in the same line but I can't think of a different solution. I tried to separate those two commands in the list with "[CTRL J]" or with "+" instead of with "&&" but, that way, the script doesn't work even when launched by CLI...

Any help would be very appreciated!
Thanks in advance!

PS:
This is the original script from Retrofan:
Code:
list >ram:startgame "`randomfile Work:Games/#?/#?/#?.slave Sys:Utilities/EXPANSION/Opus5/Sounds/BootSounds/Trackingfile2`" lformat="cd *"%p*"*nWHDLOAD *"%n*" PRELOAD"
execute ram:startgame
I can't use it since I don't have Opus5.
liviux76 is offline  
Old 05 August 2015, 22:01   #2
Arnie
R.I.P Smudge 18-08-16
 
Arnie's Avatar
 
Join Date: Aug 2005
Location: Leicester/UK
Age: 66
Posts: 3,968
Can you drop the 'lformat="cd' from the scrpt?
Arnie is offline  
Old 05 August 2015, 22:22   #3
liviux76
Registered User
 
liviux76's Avatar
 
Join Date: Jan 2014
Location: BO/Italy
Posts: 711
Quote:
Originally Posted by Arnie View Post
Can you drop the 'lformat="cd' from the scrpt?
Do you mean modify the output of "list" in order to have a line like this?

Code:
C:WHDLoad Data:WHDLoad/R/RiseOfTheDragon/RiseOfTheDragon.Slave PRELOAD
I could try...
liviux76 is offline  
Old 05 August 2015, 23:49   #4
liviux76
Registered User
 
liviux76's Avatar
 
Join Date: Jan 2014
Location: BO/Italy
Posts: 711
No luck...

I modified the script this way:

Code:
list Data:WHDLoad/#?/#?/#?.slave >RAM:prg.list lformat="C:WHDLoad %p*%n* PRELOAD"
in order to obtain the lines in the list as follows:

Code:
C:WHDLoad Data:WHDLoad/R/RiseOfTheDragon/RiseOfTheDragon.Slave PRELOAD
but now I receive an error from WHDLoad:

Code:
WHDLoad 18.1
DOS ERROR 205
Object Not Found:
I think that the "cd" command is necessary. This way the script doesn't work even if run from CLI...

Last edited by liviux76; 06 August 2015 at 00:18.
liviux76 is offline  
Old 06 August 2015, 09:44   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Check your s:shell-startup file, it probably contains something like

set _mchar "&&"

You have to put this at the beginning of your script, too. Otherwise it is not possible to execute two commands from one line.

And if you want to share your script with others, you have to tell them that they need the Pipe command. http://aminet.net/package/util/shell/Pipe-1.5
thomas is offline  
Old 06 August 2015, 11:02   #6
liviux76
Registered User
 
liviux76's Avatar
 
Join Date: Jan 2014
Location: BO/Italy
Posts: 711
@thomas

hey man! You did it!

Yes, I did install pipe a few days ago but I didn't know that the "&&" was working in the shell for that reason.

Adding the string you suggested at the top of the script (just after .KEY PRG) did the trick and now it works even when run through iconx.

I haven't decide yet if using randome or pickfile, both seem to work well.
liviux76 is offline  
Old 26 January 2017, 19:53   #7
volvo_0ne
Registered User
 
Join Date: Mar 2015
Location: Sheffield UK
Posts: 360
Help!!!

Rather than open a new thread, can someone please remind me how to use the CONTENTS of a file as a pointer...

To explain

I have a file located at RAM:somedata.dat

That file contains the following string DH0:PROJECTS/someproject.prj

In my script I want to do something like...

IF EXISTS RAM:somedata.dat
someapp.exe (the contents of)RAM:somedata.dat
EndIF

with the end result being ..

someapp.exe DH0:PROJECTS/someproject.prj

someapp.exe is an application which needs someproject.prj to work with.

In the 90's I would have sorted this in seconds, but time & alcohol has taken it's toll on my grey matter.

TIA for any help
volvo_0ne is offline  
Old 26 January 2017, 20:05   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
If you put the file into ENV: rather than RAM: you could use

someapp.exe ${somedata.dat}

For a general file containing just one line you could use Type:

someapp.exe `type RAM:somedata.dat`

`is a left-directed accent (French "accent grave").
thomas is offline  
Old 09 November 2017, 16:20   #9
kolla
Banned
 
Join Date: Nov 2007
Location: Trondheim, Norway
Posts: 1,893
Also known as "back-tick".

I have been wanting to ask ThoR if he may consider an alternative to back-ticking, since it so often is confusion with the trio of `'ยด. Posix shells has since long now used $(command), which is so much easier to communicate
kolla 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
RebootStart script help! Overkill support.Other 43 23 April 2013 17:52
Execute a script frikilokooo project.ClassicWB 6 20 November 2007 11:36
AmigaDos script file help. T_hairy_bootson support.Apps 0 07 March 2006 10:15
The zone script fairchild project.EAB 3 21 April 2005 20:28
New Installer Script BenniP request.UAE Wishlist 16 22 June 2004 09:55

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 23:55.

Top

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