Grabbing a named parameter with Parse?

A forum dedicated to George scripting questions
Post Reply
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Grabbing a named parameter with Parse?

Post by KenC »

Say you're looking for the step size of a brush, just an example.

If you run this with the cutbrush active you can see my dilemma, it's monstrous :)

tv_getactivetool
Print result

I need the stepsize in this example no matter what brush is currently selected.

The problem comes because you can't count on "step" always being in the same position in the result variable, some brushes doesn't even have step.

Isn't there a way to do something like:

Parse Result "Step" MyStepSize

Or just some function that splits the result variable into an array so I can loop through it to grab what I need.
There's no place like ~/
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Grabbing a named parameter with Parse?

Post by Svengali »

Hi Ken,
This puzzled me for a while but experimenting I came up with this:

Code: Select all

tv_GetActiveTool
parse result Tool
parse result ToolType d // d = dummy so we are parsing out only the type of tool

IF CMP(ToolType, "tv_restorebrush")
    tv_BrushRestore Size
    parse result d BrushSize  // again we use a dummy to parse only the brush value
//    tv_warn BrushSize  // remove comment to report current brush size
	BrushSize = BrushSize - 5
	IF BrushSize < 5
		BrushSize = 5
	END
	tv_cmd Tool  // restores settings as acquiring individual parameter resets all others
	tv_BrushRestore Size BrushSize
END
Sven
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Grabbing a named parameter with Parse?

Post by KenC »

Thanks a lot Sven.

That also gave me a clue on how to parse "Result" into an array, just use that technique to hack off one value at a time and reparse the last dummy that will contain the rest and then stick each one into the array.

I tried using the built in functions like CHAR but it barfs on me when using a counter instead of a literal number like this

StrLen = LEN(Result)

For i=1 to StrLen
Print CHAR(Result,i)
END

This bombs with an execution error, because of using the counter variable "i" I'm guessing?

If I do this

Print CHAR(Result,5)

Then it works?
There's no place like ~/
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Grabbing a named parameter with Parse?

Post by KenC »

arrrrrgh so close but no cigar.

When parse doesn't have anything more to parse (String parsed is empty) it sticks "0" in there so now I can't check for a blank string to know when to bail from a while loop because the Result variable can contain 0 as part of a brush's value. :(

I guess I can do something ugly like sticking my own "end of line" character on to the result string.
There's no place like ~/
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Grabbing a named parameter with Parse?

Post by Svengali »

Ken,

Do you have the basic and advanced include files usually found in the George\Include subdirectory? If not, you should request them from TVPaint Headquarters.

Sven
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Grabbing a named parameter with Parse?

Post by KenC »

no they weren't installed with my version of tvpaint, there wasn't even the george folder so I just hacked my way so far :D

I'll send an email requesting it, thanks.

An updated SDK would also be lovely :wink:
There's no place like ~/
Post Reply