FG Spreadshirt Swag
  1. #1

    Have you ever used ChatGPT help you program? You should!

    It's amazing. It is nearly spot on, the example using the number of rolled dices ist perfect but still, just amazing.

    Q: Can you explain this lua code? local sSign, sColor, sDieSides = vDie.type:match("^([%-%+]?)([dDrRgGbBpP])([%dF]+)");

    A: Certainly! This code is using a Lua string pattern matching function to parse a string that represents a dice roll notation, such as "2d6" or "-1d20".

    Here's what each part of the code means:
    local sSign, sColor, sDieSides declares three local variables that will be used to store the values extracted from the string.

    vDie.type is the string that we want to extract values from.

    :match("^([%-%+]?)([dDrRgGbBpP])([%dF]+)") is a Lua string pattern matching function that attempts to match the string against a given pattern. The pattern is defined inside the parentheses.
    "^([%-%+]?)([dDrRgGbBpP])([%dF]+)" is the string pattern that we're matching against. Here's what each part of the pattern means:

    * ^ means that the match should start at the beginning of the string.
    * ([%-%+]?)([dDrRgGbBpP]) is a pattern that matches a sign (+ or -), followed by a letter that represents the type of die being rolled (d, D, r, R, g, G, b, B, p, or P). The () brackets create capture groups that can be used to extract the matched values later on.
    * ([%dF]+) is a pattern that matches one or more digits (0-9) or the letter "F". This represents the number of dice being rolled or a fixed value, such as "F" for a flat bonus. Again, the () brackets create a capture group for this value.

    So when we run vDie.type:match("^([%-%+]?)([dDrRgGbBpP])([%dF]+)"), Lua will attempt to match the pattern against the vDie.type string. If the string matches the pattern, the match() function will return three values: the sign, the die type, and the number of dice or fixed value. These values are stored in the sSign, sColor, and sDieSides variables, respectively.

    For example, if vDie.type is "-2d6", then the match() function will return "-" as the sign, "d" as the die type, and "2" as the number of dice. These values will be stored in the sSign, sColor, and sDieSides variables, respectively
    Last edited by Mephisto; April 2nd, 2023 at 13:36.

  2. #2
    I love the code explanation! It usually is very good and often can appear to infer accurate information from variable names.

    HOWEVER:

    ChatGPT knows basically nothing about FG (even FG as it was back in 2021).
    So when I asked it to tell me about how the DB API works it just spewed out a bunch of incorrect information:
    image.png

    So at least until someone creates a 'training prompt' to tell it about all the official API functions (as was recently done for effect creation), you should just be aware that its answers will be of varying accuracy. Even once that has happened, you still need to be on the lookout for inaccurate information it presents with the certainty of fact.
    Last edited by bmos; April 3rd, 2023 at 11:55.

  3. #3
    I totally agree. To get a general idea, especially about lua, it is really helpfull.

  4. #4
    All LLM are great at explaining things, as long as you are ok with it being factually wrong. So, it is very helpful on areas where you do have some expertise, but it might be a risky hazard on areas where you have no idea if it the algorithm is just dumping random facts that are language-statistically correct. I like your regular expression example, but there are other sites that would do a much better job (including allowing you to test different variations of the expression, in lua).

    Another point to remember is that you can't really "train" the existing LLMs. You can give context for a given session to iterate on responses, but those are not added to the model (unless retrained with data from previous sessions data, which is usually a not great idea).
    Daniel Salles de Araújo (@dsaraujo)
    Developer of PFRPG2 GM Enhancements - Improve your Pathfinder 2E game!
    Check out the Pathfinder Deck of Endless NPCs!

  5. #5
    I would note that it was wrong for part of it. It wouldn't return the 2 as that string is not looking for that. It is supposed to return the 6 as the number of sides instead.

  6. #6
    Quote Originally Posted by dsaraujo View Post
    I like your regular expression example, but there are other sites that would do a much better job (including allowing you to test different variations of the expression, in lua).
    Do you have links to these sites?

  7. #7
    Quote Originally Posted by DCrumb View Post
    I would note that it was wrong for part of it. It wouldn't return the 2 as that string is not looking for that. It is supposed to return the 6 as the number of sides instead.
    Yes, not perfect. But to get the idea, I liked it.

  8. #8
    Quote Originally Posted by Mephisto View Post
    Do you have links to these sites?
    This is the best site I know for working with Lua-style pattern matching:
    https://gitspartv.github.io/lua-patterns/
    Last edited by bmos; April 3rd, 2023 at 11:55.

  9. #9
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,678
    Blog Entries
    1
    Quote Originally Posted by DCrumb View Post
    I would note that it was wrong for part of it. It wouldn't return the 2 as that string is not looking for that. It is supposed to return the 6 as the number of sides instead.
    shouldnt it return -2, d, 6 ??

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in