Results 1 to 8 of 8

Thread: How to use an alias within an alias?

  1. #1

    Default How to use an alias within an alias?

    I have an alias called 'inferno' that goes to the volcano and chooses the -1 drunkenness option. I want to put this alias inside of another one called 'consume' that does my daily consumptions, but it gives an error saying that it doesn't recognize the command. It actually used to work in the past, but at some point that changed. Here is what the two commands look like:

    Code:
    inferno => outfit inferno; ashq visit_url("place.php?whichplace=airport_hot&action=airport4_zone1"); visit_url("choice.php?whichchoice=1090&option=5")
    
    consume => use milk o; eat 3 spooky hi; cast 2 ode; drink 6 perf dark; inferno; drink 2 cold one; chew 3 powdered gold; use mojo f; chew powdered g
    Any help is much appreciated

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,812

    Default

    You might want to use scripts instead. Just
    1) place files named "inferno" and "consume" anywhere in mafias scripts/ folder (they can be in a subfolder, I do that for all my private scripts)
    2) place the commands you had in those aliases into the appropriate script files (you can even place one per line!)
    3) remove the aliases

    This will also decouple your code from mafia, so you have even lower chance of it getting corrupted when mafia gets corrupted.


    (I might remember wrong, but aliases *might* have been made to not work in places other than start of line, for safety reasons)

  3. #3
    Developer
    Join Date
    Aug 2009
    Posts
    2,796

    Default

    (I might remember wrong, but aliases *might* have been made to not work in places other than start of line, for safety reasons)
    Originally Posted by xKiv View Post
    The code (persistence/Aliases.java) seems to agree with you. I didn't look at the blame, so I can't verify the reasoning.

    Also, it is possible to do this via cli_execute shenanigans, but I agree with xKiv that you're probably better suited just writing a script and/or composing them.
    Code:
     > alias bar => echo 1
    String successfully aliased.
    bar => echo 1
    
     > alias foo => echo 2; cli_execute bar
    String successfully aliased.
    foo => echo 2; cli_execute bar
    
     > foo
    2
    1
    I absolutely do not endorse writing code in this fashion...

  4. #4
    Developer
    Join Date
    Aug 2009
    Posts
    2,796

    Default

    (also, "alias bar => cli_execute bar" is a way to generate a stack overflow)

  5. #5

    Default

    Hmm, I don't remember any change to make aliases only work at the start of the line. I do remember a bug report from maybe a year ago that was actually due to an alias the user had forgotten.

    To ensure that an alias will only run at the start of the line, you can do
    Code:
    alias bar %% => whatever here
    That's obviously the opposite of what the thread asked for, but I would agree that all that code probably belongs in a script instead.

  6. #6
    Developer
    Join Date
    Aug 2009
    Posts
    2,796

    Default

    Hmm, I don't remember any change to make aliases only work at the start of the line. I do remember a bug report from maybe a year ago that was actually due to an alias the user had forgotten.
    Originally Posted by lostcalpolydude View Post
    Ah, right you are. I'd only skimmed the code briefly. It looks like the root cause is that we only resolve one layer of aliases via the invocation to Aliases.apply in KoLmafiaCLI.java.

  7. #7

    Default

    Thanks for the help. How does one remove an alias?

  8. #8

    Default

    > help alias

    alias [ filter ] | [ word => expansion ] - list aliases [matching filter] or create CLI abbreviations.
    unalias word - remove a CLI abbreviation.

Posting Permissions

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