Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 21 to 30 of 35

Thread: Is there a way to read a file in to a buffer?

  1. #21
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,641

    Default Re: Is there a way to read a file in to a buffer?

    I like it. It doesn't allow ASH to access the current ccs, which was part of the OP's request, but it allows scripts to provide specific ccs's for specific instances, which is exactly what the OP ordered.

    These "consult functions" should also be allowed to pass combat back to mafia without doing anything, which I seem to recall normal consult scripts are not able to do.

    EDIT: Perhaps it could also accept filenames? If the third parameter ends in ".ash" or no function exists in the namespace by that name, search the script paths for a ccs and use that. I'm thinking of scripters who like the functionality but might not be up to the implementation of writing a full consult function.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  2. #22
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default Re: Is there a way to read a file in to a buffer?

    If you could make the current ccs available - just as a big buffer
    buffer current_ccs()
    that would rock the situation. Mafia's string handling capabilities are good enough that it doesn't have to be anything fancier than that.
    My scripts: Ascend for automatic ascensions, Farm to make more money than castlefarming, EatDrink for the maximum number of turns each day, LevelUp to gain a level safely, and PullCrap to manage your pulls in ronin.

  3. #23
    Developer jasonharper's Avatar
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    1,122

    Default Re: Is there a way to read a file in to a buffer?

    Ok, here's what I've come up with as a workable implementation of in-script combat customization. It ended up as neither CCS nor consult, but an unholy chimera of the two. Fortunately, unstable DNA is readily available at the moment!

    There would be a version of adventure() that takes a third string argument, naming a function.

    That function should have a signature like this:
    string my_consult_function(int round, monster opponent, string pageText)

    'round' starts at zero, and is incremented by one on each successive call to your function. It's not exactly the same as the combat round number, since there are actions that take no rounds (such as "steal" when that's unavailable or inappropriate), and actions that take more than one round (skill use with insufficient MP, thus requiring a restorative to be used first).

    The normal consult-related functions could probably be used, but there's a better way - just return a string in the form of a CCS command. (Actually, I'm surprised that this isn't the way consult scripts worked from the beginning - seems like it would have been a lot easier to implement.) It will be executed, and then, assuming that the combat hasn't been finished or aborted, your function will be called again to produce the next action. Note that, unlike existing consult scripts, your script isn't being reloaded each time, so you've got continuity of global variables between each call.

    To allow your function to modify the user's combat strategy rather than completely replacing it, there would be one new built-in function:
    string get_ccs_action(int round)
    It will return the specified line from the CCS section appropriate for the monster currently being fought (which therefore makes this function only usable from within a consult function). Numbers past the end of the CCS will return copies of the last line. It will transparently handle switching to a different CCS section after a "default" command or use of CLEESH - complications that would make it difficult to provide a version of the function that allowed you to explicitly specify a section. Also, if the user has specified a simple battle action instead of a CCS, this function will make it look as if they had a CCS that read:
    1: steal
    2: <their battle action>

    So, a minimal do-nothing consult function would look like this:
    Code:
    string null_consult(int round, string opp, string text) {
      return get_ccs_action(round);
    }
    
    adventure(1, $location[whatever], "null_consult");
    And one that inserts an action into the user's strategy might look like this:
    Code:
    int insertRound = 2;
    string insertAction = "item meat vortex";
    
    string insert_consult(int round, string opp, string text) {
      if (round == insertRound) return insertAction;
      else if (round > insertRound) round = round - 1;
      return get_ccs_action(round);
    }
    To make that really useful, you'd need to scan the CCS to determine the right place to insert the action - perhaps after any "steal" or "skill entangling noodles" command, but before anything that can kill the monster.

    Now the big question: does this meet everyone's needs?
    In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)

  4. #24
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,641

    Default Re: Is there a way to read a file in to a buffer?

    I would imagine a common practice would be checking for an action's presence in the ccs, which would require foreaching through get_ccs_action(1-30). If the action is present, no special handling is needed. With this implementation, another function boolean action_exists(string action), which like get_ccs_action() would only be callable from within a consult function, would be a very nice addition. It should probably also do partial matching.

    I would also imagine common practice would be to perform a variety of actions (probably taking multiple rounds) at the beginning of the combat, ignoring the existing ccs, then handing combat back to mafia. Would this implementation still allow a consult function to do something like:

    Code:
    string ccs_for_brigands(int round, string opp, string text) {
      if (have_skill($skill[entangling noodles]) && monster_attack() > my_buffedstat($stat[moxie]) + 4)
       use_skill($skill[entangling noodles]);
      if (item_amount($item[meat vortex]) > 0) throw_item($item[meat vortex]);
      run_combat();
    }
    
    adventure(my_adventures(),$location[themthar hills],"ccs_for_brigands")
    And if so, what "round" would mafia think it is for continuing with an existing ccs when run_combat() is called?

    Anyway, any of the above mentioned methods, including this "unholy chimera" would be awesome as far as I'm concerned.

    EDIT: Better idea than run_combat(): the function could return "done" or "handoff" or some such, whereupon mafia would resume handling the combat, and the consult function would no longer be called.

    So, if my suggestions were all worked into the chimera:

    Code:
    string ccs_for_brigands(int round, string opp, string text) {
      if (ccs_contains_action("meat vortex")) return "done";
      if (have_skill($skill[entangling noodles]) && monster_attack() > my_buffedstat($stat[moxie]) + 4)
       use_skill($skill[entangling noodles]);
      if (item_amount($item[meat vortex]) > 0) throw_item($item[meat vortex]);
      return "done";
    }
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  5. #25
    Developer jasonharper's Avatar
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    1,122

    Default Re: Is there a way to read a file in to a buffer?

    action_exists() could be easily and efficiently written in ASH; in fact it might even be more efficient in ASH since you could check for multiple things in a single pass through the CCS.

    run_combat() wouldn't work in a consult function: it would just call the function again as it tried to determine the next round's action. Also, there's a syntax error in your example - the function has to return something, which would be executed after the combat was actually over if run_combat() worked.

    The problem with returning "done" as you suggest is that mafia wouldn't know what line number in the CCS to continue from. I don't see any easy way around needing to pass every action through the consult function - perhaps "combat filter" would be a better name for it. It's likely that you'd have a global 'offset' variable, increased by 1 every time you insert a command that didn't come from the CCS, then just do return get_ccs_action(round - offset); after all insertions have been done.

    Another possible approach:
    1. On round 0, read the entire CCS into a map or array, or perhaps concatenate it all into one big string.
    2. Perform whatever modifications you want to that representation (action_exists() becomes particularly simple if everything's in a string!).
    3. Return elements from the data structure one by one.
    In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)

  6. #26
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,641

    Default Re: Is there a way to read a file in to a buffer?

    Yeah, agreed on run_combat()... that's why I thought "done" would work better. I still think a way to exit the consult function is necessary, though. It would probably work just fine if "done" popped back out on round 1, since consult functions could easily avoid duplicate actions using action_exists(). Either that or the function could return "done 3" or whatever round number we wanted mafia to think it was for purposes of the ccs.

    Also, for flexibility, action_exists() should return an int -- the round where the action was found, or -1 for not found. This would allow for the detection of disco combos.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  7. #27
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default Re: Is there a way to read a file in to a buffer?

    Love how this is going, but one thing - it seems to make it overly complicated to do the simplest thing, which is "Append X to the start of my battle". Or am I missing a way to do that easily?

    Also, for no reason I can describe, I'd rather know that the CCS actually said to attack 30 times, vs. that it simply said "attack". So I think I'd prefer calls to undefined rounds to return "" instead of the last specified entry. Probably because you can calculate the second information from the first, but not vice versa.

    Otherwise, awesome.
    My scripts: Ascend for automatic ascensions, Farm to make more money than castlefarming, EatDrink for the maximum number of turns each day, LevelUp to gain a level safely, and PullCrap to manage your pulls in ronin.

  8. #28
    Developer jasonharper's Avatar
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    1,122

    Default Re: Is there a way to read a file in to a buffer?

    I showed how a function that inserts an action at an arbitrary location would look - appending to the start would be the same thing, with a location of 0. Is a 3-line function really that complicated?

    [quote author=dj_d link=topic=2130.msg11068#msg11068 date=1231918828]Also, for no reason I can describe, I'd rather know that the CCS actually said to attack 30 times, vs. that it simply said "attack". So I think I'd prefer calls to undefined rounds to return "" instead of the last specified entry. Probably because you can calculate the second information from the first, but not vice versa.[/quote]

    There is no observable difference between a CCS that says "attack" 30 times versus once, so what exactly could you do with this knowledge? This couldn't easily be implemented anyway, since the expected use of the return value of get_ccs_action() is for you to return it from your consult function - how would mafia know what to do if it received ""?
    In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)

  9. #29
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,641

    Default Re: Is there a way to read a file in to a buffer?

    [quote author=dj_d link=topic=2130.msg11068#msg11068 date=1231918828]
    the simplest thing, which is "Append X to the start of my battle".
    [/quote]

    What Jason described:

    Code:
    // adds salve to beginning of combat if it doesn't already exist in the ccs
    string insert_consult(int round, string opp, string text) {
      if (action_exists("salve")) return get_ccs_action(round);
      else {
        if (round == 1) return "salve";
        if (round > 1) round = round - 1;      // compensate for insertion
        return get_ccs_action(round);        // for the rest of the combat, executes your existing ccs
      }
    }
    What I described:

    Code:
    // does the same as above
    string insert_consult(int round, string opp, string text) {
      if (!action_exists("salve") && my_mp() >= mp_cost($skill[saucy salve]))
        use_skill($skill[saucy salve]);
      return "done 1";               // mafia resumes your ccs from round 1
    }
    Either way, it isn't too terribly complicated.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  10. #30
    Developer jasonharper's Avatar
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    1,122

    Default Re: Is there a way to read a file in to a buffer?

    The combat filter feature has been added in r6789. Go kill monsters with it!

    Note that it doesn't behave particularly well if the filter function doesn't exist, or is declared improperly. Here's an odd case: if the function is mistakenly declared to return void rather than a string, the string "void" is what ends up getting passed to the combat machinery - which happens to match the "ovoid leather thing" combat item. It took me a while to figure out why my test script was doing nothing other than trying to use that item!
    In game: Seventh (#363053), originally a Seal clubber. I am the Ap'ostle of Ak'gyxoth! (Or is that Ap'ostrophe?)

Similar Threads

  1. Replies: 0
    Last Post: 09-08-2014, 11:53 AM
  2. gCLI buffer - can it be made larger or piped to a file?
    By Magus_Prime in forum Community Support
    Replies: 9
    Last Post: 06-21-2013, 06:28 PM
  3. Replies: 0
    Last Post: 02-10-2012, 11:50 PM
  4. Replies: 0
    Last Post: 02-01-2011, 02:11 PM

Posting Permissions

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