PDA

View Full Version : Have you ever used ChatGPT help you program? You should!



Mephisto
April 2nd, 2023, 13:27
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

bmos
April 2nd, 2023, 13:49
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:
56931

So at least until someone creates a 'training prompt' to tell it about all the official API functions (as was recently done (https://www.fantasygrounds.com/forums/showthread.php?77335-Using-ChatGPT-for-easier-effect-codings-Tutorial) 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.

Mephisto
April 2nd, 2023, 13:58
I totally agree. To get a general idea, especially about lua, it is really helpfull.

dsaraujo
April 2nd, 2023, 16:58
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).

DCrumb
April 2nd, 2023, 17:31
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.

Mephisto
April 2nd, 2023, 17:50
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?

Mephisto
April 2nd, 2023, 17:51
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. :o

bmos
April 2nd, 2023, 22:50
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/

damned
April 2nd, 2023, 22:53
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 ??