Results 1 to 8 of 8

Thread: GetScriptName

  1. #1
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default GetScriptName

    I'm not terribly used to not simply being able to find a solution to a question via google or the API, but this time I'm a little stumped it appears.

    How would I go about getting the actual currently running script name using code?

    ScriptPath will grab the entire path up to the name, but what would grab the actual script name itself?

  2. #2
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    I'm not terribly used to not simply being able to find a solution to a question via google or the API, but this time I'm a little stumped it appears.

    How would I go about getting the actual currently running script name using code?

    ScriptPath will grab the entire path up to the name, but what would grab the actual script name itself?
    Hey Kevin,

    You can use ScriptFile to get the script name:

    Code:
    begin
      WriteLn(ScriptFile);
    end.
    If your script is unsaved, it returns as '' (empty string).

    When you'll save it, result would be something like this (depending of the name you save it as):

    Code:
    Compiled successfully in 31 ms.
    test.simba
    Successfully executed.
    So, I saved mine as "test".

  3. #3
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    Hey Kevin,

    You can use ScriptFile to get the script name:

    Code:
    begin
      WriteLn(ScriptFile);
    end.
    If your script is unsaved, it returns as '' (empty string).

    When you'll save it, result would be something like this (depending of the name you save it as):

    Code:
    Compiled successfully in 31 ms.
    test.simba
    Successfully executed.
    So, I saved mine as "test".
    Thank you for that very much! That's exactly what I was looking for

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    Thank you for that very much! That's exactly what I was looking for
    No problem, mate!

    By the way, I wrote a custom little function which doesn't include the file extension to the result..
    It also returns as "Untitled" when script hasn't been saved.

    Check this out:

    Code:
    function ScriptName: string;
    var
      p, o: Integer;
    begin
      Result := ScriptFile;
      case (Result = '') of
        False:
        if (Pos('.', Result) > 0) then
        begin
          o := 1;
          repeat
            p := PosEx('.', Result, o);
            if (p > 0) then
              o := (p + 1);
          until (p = 0);
          Result := Copy(Result, 1, (o - 2));
        end;
        True: Result := 'Untitled';
      end;
    end;
    
    begin
      ClearDebug;
      WriteLn(ScriptName);
    end.

  5. #5
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    No problem, mate!

    By the way, I wrote a custom little function which doesn't include the file extension to the result..
    It also returns as "Untitled" when script hasn't been saved.

    Check this out:

    Code:
    function ScriptName: string;
    var
      p, o: Integer;
    begin
      Result := ScriptFile;
      case (Result = '') of
        False:
        if (Pos('.', Result) > 0) then
        begin
          o := 1;
          repeat
            p := PosEx('.', Result, o);
            if (p > 0) then
              o := (p + 1);
          until (p = 0);
          Result := Copy(Result, 1, (o - 2));
        end;
        True: Result := 'Untitled';
      end;
    end;
    
    begin
      ClearDebug;
      WriteLn(ScriptName);
    end.
    I know usually it's compiler dependent as to when Switch statements are more efficient than if/elseif statements, but in this case, wouldn't an if/else be more efficient?

    Also, considering differing naming standards, can scripts ever have an extension outside of .simba? As it stands, if someone chose to name their script Fighter.V2.simba, or Fighter.Roaches.simba this method would only grab the "Fighter" portion of the name. Absolutely feel free to correct any mistakes I have in assumptions or concepts, but wouldn't an approach like this cover more scenarios then:

    Simba Code:
    function ScriptName: string;
    var
      p, o: Integer;
      lower: String;
    begin
      Result := ScriptFile;
      if(Result <> '')then
      begin
        lower:= Lowercase(Result);
        if (Pos('.simba', lower) > 0) then
        begin
          o := 1;
          repeat
            p := PosEx('.simba', lower, o);
            if (p > 0) then
              o := (p + 1);
          until (p = 0);
          Result := Copy(Result, 1, (o - 2));
        end;
      end else
        Result := 'Untitled';
    end;

    Edit: Would ScriptName be in some other include besides srl.simba by chance?

  6. #6
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    I know usually it's compiler dependent as to when Switch statements are more efficient than if/elseif statements, but in this case, wouldn't an if/else be more efficient?

    Also, considering differing naming standards, can scripts ever have an extension outside of .simba? As it stands, if someone chose to name their script Fighter.V2.simba, or Fighter.Roaches.simba this method would only grab the "Fighter" portion of the name. Absolutely feel free to correct any mistakes I have in assumptions or concepts, but wouldn't an approach like this cover more scenarios then:

    Simba Code:
    function ScriptName: string;
    var
      p, o: Integer;
      lower: String;
    begin
      Result := ScriptFile;
      if(Result <> '')then
      begin
        lower:= Lowercase(Result);
        if (Pos('.simba', lower) > 0) then
        begin
          o := 1;
          repeat
            p := PosEx('.simba', lower, o);
            if (p > 0) then
              o := (p + 1);
          until (p = 0);
          Result := Copy(Result, 1, (o - 2));
        end;
      end else
        Result := 'Untitled';
    end;

    Edit: Would ScriptName be in some other include besides srl.simba by chance?
    I wrote it to find the last "." position in result (hence why, PosEx in repeat..until loop), that means the function I wrote works with just any extension!
    ..and yes, someone could run script from say... .TXT file.
    So, scripts aren't limited to .simba extension - at 1 point, in the past, there were still some scripts that used .scar extension.

    Not really sure, if it matters whether its an if..then or case..of with such a small task really - might be a different story if that case would be inside a massive loop.

    About ScriptName, I can't tell if it is, I don't use SRL include. :\ If you got "Duplicate identifier" -error, then it definitely is..

  7. #7
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    I wrote it to find the last "." position in result (hence why, PosEx in repeat..until loop), that means the function I wrote works with just any extension!
    ..and yes, someone could run script from say... .TXT file.
    So, scripts aren't limited to .simba extension - at 1 point, in the past, there were still some scripts that used .scar extension.

    Not really sure, if it matters whether its an if..then or case..of with such a small task really - might be a different story if that case would be inside a massive loop.

    About ScriptName, I can't tell if it is, I don't use SRL include. :\ If you got "Duplicate identifier" -error, then it definitely is..
    Ah, see I didn't know that we could run from any extension. I can see that much better now, thank you. And yeah, scale on 1 iteration is pretty insignificant.

    As for the ScriptName in SRL, I was actually helping @The Killer from work and that was a temporary issue he asked me about that I had trouble checking at the moment

    So why don't you use SRL? Are you just around here for the company (let's be honest, we're pretty awesome), without care for the purpose as to why most of us are here?

  8. #8
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    *snip*
    Mostly it's because SRL include is so heavily built around RuneScape cheating (even though there are several miscellaneous functions/procedures that work for other things aswell) and I don't play RuneScape anymore. I don't even run macros/bots in it.
    I used to play RuneScape from 2001-2004 (Classic), but I was never into RS2.
    ..although, I did write couple includes in MSSL for Project RS06 & RuneScape 2007 ("Old School") and several scripts based on those includes, but all that was mostly for learning new tricks with SCAR, not for any personal use or so on...

    The reason why I stick around, is that I do enjoy staying around over here @SRL community.
    This community full of mature and friendly people, who are really creative, innovative and talended when it comes to coding (scripting/programming)!
    So, I really can't disagree with you, this community is awesome indeed.

    Personally I am trying to give back to this community as much as I just can - that is, by contributing stuff and helping out people with any problems/issues that I can help them with.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •