SRL Archive - FAQ

Possible to write a script that'll execute another script?


Sin

2014-08-31 20:51:52

Is it possible to get Simba to execute a script which in turn executes other scripts in a specific order?
Or will I just have to copy both scripts into one gigantic script and create a task system kinda thing?

rj

2014-08-31 21:34:43

no.

Well. I guess you could look at the source of Simba and see whatever the 'play' button does and make a plugin. I don't know though. Would probably need to link the compiler in your plugin or something

https://github.com/MerlijnWajer/Simba/blob/5b8bb19cd5c3c08b9ee67c45f62fe2da2f0f218f/Projects/Simba/simbaunit.pas

Olly

2014-08-31 22:09:23

No you couldn't do it via a plugin. It's possible to add but it's not currently possible.

rj

2014-08-31 22:15:13

From: Olly
No you couldn't do it via a plugin. It's possible to add but it's not currently possible.


you can't create a plugin that would give a files information to the compiler to run?

Olly

2014-08-31 22:20:43

From: Robert
you can't create a plugin that would give a files information to the compiler to run?


No.

rj

2014-08-31 22:34:18

From: Olly
No.


why

Olly

2014-08-31 22:42:33

From: Robert
why


because you can't tell a plugin to just tell simba to open a script…

Lipcot

2014-08-31 22:43:27

i´ve always wondered about this heh

rj

2014-08-31 23:26:01

From: Olly
because you can't tell a plugin to just tell simba to open a script…


but you can make a plugin that can read the contents of simba scripts and compile them yes?

Olly

2014-08-31 23:42:49

From: Robert
but you can make a plugin that can read the contents of simba scripts and compile them yes?


I assume… Though you would pretty much be copying 90% of Simba in a plugin…

Turpinator

2014-09-01 01:14:15

i mean… you /could/ have a script read in another script from an existing file, spawn a new simba, type the code then run… but it would be rather… 'janky'

as i do here. https://villavu.com/forum/showthread.php?t=105393&p=1261471#post1261471

cosmasjdz

2014-09-01 12:23:48

or you could use sharedtabs include to make scripts conversation between them. Thats how iv mined rune ore in f2p, miner mining, runners running.

tls

2014-09-01 12:51:41

From: cosmasjdz
or you could use sharedtabs include to make scripts conversation between them. Thats how iv mined rune ore in f2p, miner mining, runners running.


Or just use sockets.

Brandon

2014-09-01 14:48:16

Sockets really are a good way to go.. but for the sake of answering your question, it actually is/was possible..


var
ScriptName: String;
TP: TProcess;
begin
ScriptName := 'Test.Simba';

TP.Init(nil);
TP.setCommandLine(ScriptPath + 'Simba.exe -o ' + ScriptPath + 'Scripts\' + ScriptName);
TP.Execute();
TP.Free();
end.


Will open Simba with the script you desire.. I cannot remember the command/flag to make it play but there is one.. I just need to find where I last saw it (in one of my very first posts).. It's in one of my very first C++ posts.. Just not sure where or if I posted it using this account or my first account (which I don't remember the pw to).

I believe it was '/r' or '-r' or something but I really don't remember.. However, that's how I used to run scripts from C++ by embedding Simba into the resources of the EXE and running it from there..

EDIT: Found someone else that did it: https://villavu.com/forum/showthread.php?t=73840

Doesn't seem to work anymore but it used to :S I guess they're not wrong after all..

Olly

2014-09-01 15:28:10

From: Brandon
…


Heh I thought that was a scar only thingy.

Brandon

2014-09-01 15:52:53

From: Olly
Heh I thought that was a scar only thingy.


Nope. It used to work for Simba. Not sure what changed in Simba recently but it doesn't work for me anymore. The opening part works but the "running" part doesn't.


It used to be done like:


cmd.exe C:/Simba/Simba.exe -o C:/Simba/Scripts/TestScript.simba -r

and it'd open and run the script automatically. I used to do it using popen(http://linux.die.net/man/3/popen) or (system).


but somehow with the recent Simba releases, the "-r" part is ignored.. Not sure why.. it used to be pretty neat. You could literally embed Simba's folder into a .rar and make it auto-executable and when you double clicked it, it'd run whatever script.

It was a way to turn "Simba scripts" into ".exe" programs. Not sure why it was actually removed (the run command) but there's probably a reason I guess..

Olly

2014-09-01 16:16:02

From: Brandon
Nope. It used to work for Simba. Not sure what changed in Simba recently but it doesn't work for me anymore. The opening part works but the "running" part doesn't.


It used to be done like:


cmd.exe C:/Simba/Simba.exe -o C:/Simba/Scripts/TestScript.simba -r

and it'd open and run the script automatically. I used to do it using popen(http://linux.die.net/man/3/popen) or (system).


but somehow with the recent Simba releases, the "-r" part is ignored.. Not sure why.. it used to be pretty neat. You could literally embed Simba's folder into a .rar and make it auto-executable and when you double clicked it, it'd run whatever script.

It was a way to turn "Simba scripts" into ".exe" programs. Not sure why it was actually removed (the run command) but there's probably a reason I guess..


It works fine for me, And i just typed it into cmd and it worked. :s

Brandon

2014-09-01 16:42:21

From: Olly
It works fine for me, And i just typed it into cmd and it worked. :s


Oh it does work :S wth.. I guess my previous test script had a missing { for the loadlib directive and caused it not to compile/run..



var
ScriptName: String;
TP: TProcess;
begin
ScriptName := 'Test.Simba';

TP.Init(nil);
TP.setCommandLine(ScriptPath + 'Simba.exe -o ' + ScriptPath + 'Scripts\' + ScriptName + ' -r');
TP.Execute();
TP.Free();
end.


Works.. The script I was testing was a script that loaded a plugin and the plugin wasn't found so it did nothing.. If its just regular errors, it shows them.

I thought I was wrong & Simba broke but I guess I got it right after all :D



The above code WILL work but it is still deprecated because .setCommandLine shouldn't be used anymore..

Instead it'd have to be done like:


Function Execute(Application: String; Args: TStringArray = []): Boolean;
var
I: Integer;
Tmp: TProcess;
Begin
Tmp.Init(nil);
Tmp.setExecutable(Application);

For I := 0 To High(Args) Do
Begin
Tmp.getParameters().Add(Args[I]);
End;
Tmp.Execute();
Tmp.Free();
End;

Procedure ExecuteScript(Script: String; Path: String = ScriptPath);
Begin
If (Path = ScriptPath) Then
Path := Path + 'Scripts/';

Execute(ScriptPath + 'Simba.exe', ['-o', Path + Script, '-r']);
End;

begin
ExecuteScript('Test.Simba'); //or ExecuteScript('Test.Simba', 'C:/SomePathToScript/');
end.

Olly

2014-09-01 16:45:12

From: Brandon
Oh it does work :S wth.. I guess my previous test script had a missing { for the loadlib directive and caused it not to compile/run..

I guess I got it right after all..



var
ScriptName: String;
TP: TProcess;
begin
ScriptName := 'Test.Simba';

TP.Init(nil);
TP.setCommandLine(ScriptPath + 'Simba.exe -o ' + ScriptPath + 'Scripts\' + ScriptName + ' -r');
TP.Execute();
TP.Free();
end.


Works.. The script I was testing was a script that loaded a plugin and the plugin wasn't found so it did nothing.. I thought I was wrong but I guess I got it right after all :D


YEA! TProcess is useful for something. :D