Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Strive for Power

Fantasy Slave Management/RPG Erotic Game · By Strive4Power

[Bug] 0.5.19a regex for variables broken

A topic by Kyler2 created Sep 05, 2018 Views: 560 Replies: 4
Viewing posts 1 to 3

I think some slight typos mean it doesn't work for anything, but it was very close to functional for the intended change (match single line, and multi-line nested {}'s?). My mod breaks right now because it no longer matches my single line, and far as I can tell it won't match multi-line either in current state. The following works much better in my tests:

regex_string_dictionary["VAR"] = "(var.*=)\\s+(([\\{\\[][\n\r]+[\\S\\s]*?[\r\n]+[\\}\\]]([\r\n]+|\\Z))|([^\n\r]*))"

Matches any single-line var, and matches any var blah = {  until it hits a single line with only }

Here's an example of me debugging it: https://regex101.com/r/J9P2g2/4

Also requires some tweaks to later code, otherwise it's stripping {}'s and inserting too many lines. Here's a pastebin of entire modified modpanel.gd that works, with updated regex and later code.

https://pastebin.com/LcNwynvT

i've tested this with my mod, and a test mod to insert into the races variable.

(6 edits)

Hmm... weird.  I thought I updated the regex handling vars for 0.5.19a.  Let's see... The non-Godot (for online regex testing) should be:
(var.*=\s)(([\{\[]([^\{\}]*[\r\n]*)*[\}\]])|([^\{\}\[\]\s]*))

Does that above expression do what you want?  The double-escaped version should be what is in the modpanel.gd file as that's what I have in my working copy?
What you have doesn't look right as it still has the '?', which allows for cases like var test = {...}[random other stuff] to work.

Edit01 : Oh, maybe your v19a was before I submitted changes, but the updated version is still v19a.

Edit02: Oh pastebin.  Ya that works too. =D

(1 edit)

In v19a doesn't work for anything, mainly because it has some typos like this:

[\\{\\[]]

The double ]'s at the end there mean it tries to match a literal ]. As-is, v19a won't match practically any var. Beyond that, what you've shown here also does not work on numerous lines because of what i mentioned before, it wants every line to not contain { or }  and so it breaks on nested dictionaries.  The second half of the major | also is needlessly limiting what it can match on. It should just match everything up to the newline, otherwise it breaks on numerous valid lines.

The regex I've proposed works much better on a wide variety of use cases, the regex101 link loads it up in the unescaped form and includes several test case matches, which your proposed one, and past ones, fail on. For example, this has never worked as a new variable to insert:

var randomportraits = load(globals.modfolder + "/randomportraits/randomportraits.gd").new()

Prior regex's would always chop off part of that, then insert an invalid statement into the scripts.

Plus the later code when using AddTo was stripping {}'s which also prevented any insertion in nested dictionaries.  With the proposed modpanel.gd changes I made from v19a though, I was able to successfully test a mod to races dictionary. Should also work for multiline arrays too.

I'd recommend for future releases you make a test mod that tries to insert new and modify existing entries in several methods and make sure that #1, you can apply it, and #2 after applying the game starts without errors.

Edit: Just saw your edit3, that still does not work.  Did you try plugging that into the regex101 link I gave? That includes a bunch of test cases, and it fails on the multi-line.  Is there something wrong with the one I've proposed? I've tested it against a wide variety of test cases and successfully used it in-game.

(3 edits)

Ah you're right.  I was only thinking of simple direct variables.  For cases where a variable loads from various things, it should be pretty much open for one line.  Then handle multi-line and nested dictionaries.

And nope, just blind-vision missed your pastebin originally.   I'll look at it in regex and test/add it in 19a, but given you are using the modding system and *tested* in the online regex already, I'm gonna say your version is the most robust and correct. =D

Iit could be more robust, but at a certain point working with regex's is infuriating... I can think of more valid gdscript syntax this wouldn't currently handle, but shouldn't be the mod system's job to handle everything, only the sane things, like all multilines must be in form:
var blah = {
}

or the same with []'s, and not allow inserting anything extra after the starting or ending []{} characters.  I'm sure at some point someone will write this in a mod though and bitch it doesn't work...
var fizz = { buzz = [
"moo"
]}

What I've proposed though should work with modifying any of the existing code's current bits as they always follow that good standard as far as I've seen.

Though realized one thing I did not update.  I made AddTo work, but did not test RemoveFrom. Best guess, it works but maybe not as expected because the first line will be considered to be the { or [.