[SOLVED] Digit String-Manipulation, and a strange Shader-Glitch

  • #1, by caligarimarteMonday, 04. September 2017, 13:43 7 years ago
    Yesterday or so I have created a little System for my Game which generates Rooms for a Labyrinth or Maze according to a Code that is read when going through an Exit. While the Basics work, I also would like to refine it with two Features...

    1) ... for which I should get String of that "CaveCode"-Code turned into a Number, meaning to extract only the Numbers and ditch the Letters and an Underscore. I am not very familiar with String-Manipulation, be it in Lua or anywhere else (just not used to using it), so after some little Research I thought the following Line with a "%d+" supposedly finding all the Digits should work, but it doesn't and I don't know what I am doing wrong -- so, I'd be thankful to get some Help on this.
    Values.CaveCode.Int = tonumber(string.find("02a_00a04a03a01b","%d+"))

    Another Thing I noticed was what looks like a Glitch, but I am not sure about it. One of the Refinements I mentioned is that I want the Graphics for the Maze to be distorted depending on a Seed that shall not be random but belong to each Room's different Perspectives (so I should just extract the Digits from the CaveCode).

    2) The Problem is that when I apply a Shader to a Scene-Object, its UV will -- even if the original Graphic was filling the entire Screen -- be cut down to the Measures of actual Content abve zero Alpha. I am sure that is a good Feature for getting rid of unneeded Bytes and Megabytes being shoved into the Cache, but this is one of the Scenarios where it can be a slight Hindrance to my artistic Vision: When I use a Distortion-Shader on an Object, the Parts that should be followed by some empty Space with 0 Alpha, the UV Border is instead right where the Wall-Graphic ends, and thusly the Distortion is restricted to that Area and cannot go beyond, meaning that one Side of the Wall remains straight and undistorted, while the Rest is distorted.
    So I considered to just add some unnoticable Pixels with an Alpha-Value of maybe 2 or 3% in the opposite Corners of my Maze-Graphics, which automatically makes the Shader equally stretch across the whole Screen for each of the Graphics (because they all fill that exact Space). That Technique works for basically all Elements except the left Wall- and Exit-Graphics, which suddenly seem to have an Area which is not affected by the Shader (which becomes obvious because the Shader also colors the Graphics (because the Cave-Walls shall subtly change Color as you progress through the Maze), but not in this Area. It seems to be that Area which, at the Top and the Bottom, touches the UV-Border with Alpha above zero.
    This might not necessarily be as big a Problem once I replace my provisoric Placeholder-Graphics of just gray and white Cube-Walls with more organic and concavely shaped Cave-Walls, as their Shape would allow for the Shader to work even if the UV does not fill the entire Screen (which I guess sounds nonsensical, but it makes Sense), BUT then I would still have the Problem of the Shader's Distortion being scaled differently on different Elements, although I want the Distortion to be distributed evenly across the whole Screen.
    I suppose the more elegant Way to solve that Problem then would be to make it so the Shader's UV does not use the UV of the Object it is applied to, but that of the Screen, as if it was a Screen-Shader. But I haven't yet wrapped my Head around how to do that, even though I tried to look it up.

    So, either I have to make the Graphics all forced to be fullscreen and then get rid of that white Area, or otherwise learn how to use the Screen-UV for Effects to be applied to an Object. Any Ideas?

    Forum Fan

    145 Posts

  • #2, by SimonSMonday, 04. September 2017, 15:43 7 years ago
    What you want to do is this:

    str = "02a_00a04a03a01b"

    %D is the opposite of %d, so replace all non numeric with ''. You got to be careful with leading 0es, because lua thinks your string is hexadecimal, so I added the base 10.

    Second point, if you need the overlap, change the left upper pixel just one bit so it's not the same as the other, so the cutoff will not occur.

    Thread Captain

    1582 Posts

  • #3, by caligarimarteMonday, 04. September 2017, 18:04 7 years ago
    Thank you extensively, Simon, both Methods worked flawlessly! (I merely had to rewrite the Pattern into "[%D-0]" because later Rooms had Numbers seemingly too high for Lua process, but that was easy to fix.)

    [EDIT: I actually had hoped I could also use that numeric Value for the (to my Knowledge new) Actionpart that allows a Change once a Value has changed -- but alas, that doesn't seem to work when I put it right after the Script -- maybe it would with a Loop, but usually it works well enough if instead I just put a 1-Millisecond-Pause before loading the new Scene.]

    Forum Fan

    145 Posts