Tutorial How-to: Easy string patching

LewdWriter

Newbie
Oct 11, 2018
19
4
Sorry to revive this thread, but I am getting a script parsing error related to this code that I am at a loss on how to solve.

There error log is:
Python:
[code]
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/characters.rpy", line 26: expected statement.
    defineDynamicName mcNames:
                             ^

File "game/characters.rpy", line 36: expected statement.
    defineDynamicName dNames:
                            ^

File "game/characters.rpy", line 46: expected statement.
    defineDynamicName jNames:
                            ^

File "game/characters.rpy", line 56: expected statement.
    defineDynamicName hNames:
                            ^

File "game/characters.rpy", line 66: expected statement.
    defineDynamicName aNames:
                            ^

File "game/characters.rpy", line 77: expected statement.
    defineDynamicName pNames:
                            ^

Ren'Py Version: Ren'Py 7.1.1.929
Sat Feb 23 22:46:14 2019
[/CODE]

It seems to be saying that it expects a ':' at the end of each of those statements, but the thing is that I have a colon there in my script.

Any help would be appreciated.

Thanks!
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,109
14,783
Aha! I had it in there but had changed the name. Didn't realize that would break things. Thanks!
There's many things that happened here...

Firstly, it's important to know/remember, that the files are loaded in alphabetical order ; more exactly ANSI/UTF alphabetical order, depending of the OS and it's configuration. So a file named "0xyz.rpy" will be loaded before "XYZ.rpy", that will loaded before "xy.rpy".
Now when Ren'py load a file, at first it parse the file, then it execute all python early block in this file before loading the next file. So, when you use , like here, the file must be loader before any file using the defined statement(s), else Ren'py will not know how to parse them.
That's why while, by itself, the name of the file doesn't matter, it still need to be named so it will be loaded as early as possible ; at least before you need the statement(s) defined by it.
 
  • Like
Reactions: LewdWriter

Ohikabir

Newbie
May 2, 2021
56
33
Alright, keep in mind that it's now 2:35AM here :D

The spirit is here, and it should works. Well, except that it should be "aName[:-1]", you put the "-1" on the wrong part.
Another way to do it is this one :
Code:
        def __getattr__( self, aName ):
            if aName == "_alls": return super( DynamicNames, self).__getattribute__( aName )
            switch = aName[:1] == "_"
            if switch is True: aName = aName[1:]
            if not aName in self._alls: return "I FORGET TO SET THIS"
            aValue = ""
            for atom in self._alls[aName]: aValue += atom() if callable( atom ) else atom
            if ord( aName[:1] ) >= 97: return aValue[:1].upper() + aValue[1:]
            elif switch is True:       return aValue.upper()
            else:                      return aValue
It works like this :
t.myString -> Return the default value
t.MyString -> Return the value with a capitalized first letter
t._myString -> Return the value all in uppercase.

Both yours and mine do the same thing, and yours is way better because simpler...
I'll add it, once I can edit OP, and probably use my "_" prefix approach to do something else ; capitalized initial for each words can perhaps be useful.


Edit: Er... what I said ? No, the -1 was at the right place !!! alright, I go to sleep right now :)
Pls can u make a patch for me