Page 1 of 1

[zscript] Changing textures (and more) with zscript

Posted: Sat Mar 24, 2018 5:27 pm
by zrrion the insect
I'm wanting to play an animation when a switch is pulled. These textures will always have a name such that the first 4 characters are alpha characters and the last 4 are numbers. This should let me generalize the animation code such that I don't have to manually define the animation anywhere and can use multiple different animations on different lines that all have the same tag and they will all animate across their respective animations.

To do this I would like to do the following:
  1. Get a side that has a particular tag
  2. get the texture in the middle of that side
  3. Split the texture name into an alpha and numeric component (ABCD1234 >> ABCD 1234)
  4. Add 1 to the numeric part and reattach the numeric part
  5. If new texture exists change the middle to the new texture, otherwise repeat steps 1-5 for the next side
  6. If no sides have had their textures changed return FALSE, else return TRUE
I can do most all of this except for steps 1 and 5. I know that level.Sides will get me pointed at the sides and let me GetTexture/SetTexture but I have no idea how to get the sides I want. I'm also not super sure how to do the check to see if a texture exists or not. Everything else I can figure out.

Re: [zscript] Changing textures (and more) with zscript

Posted: Sat Mar 24, 2018 6:52 pm
by gwHero
I don't have much time for a long answer, but maybe this code I copied from my project might already help you out:

Code: Select all

const MD_LIGHTLINE_TAG = 28;
const MD_SIDE_FRONT = 0;
const MD_SIDE_BACK  = 1;

const MD_TEXTURE_TOP    = 0;
const MD_TEXTURE_MIDDLE = 1;
const MD_TEXTURE_BOTTOM = 2;

TextureId textlight = TexMan.CheckForTexture ("ZLIGHTLM", TexMan.Type_Any);
int linenum = 0;	
LineIdIterator lit = LineIdIterator.Create(MD_LIGHTLINE_TAG);			
while ((linenum = lit.Next()) >= 0)				
	level.lines[linenum].sidedef[MD_SIDE_BACK].SetTexture(MD_TEXTURE_MIDDLE, textlight);
To find lines with a tag, you can use LineIdIterator to iterate thru all the lines; with sidedef[0] (front) or sidedef[1] (back) you can refer to the sides.
If a specific texture does not exist, TexMan.CheckForTexture I believe will return -1.

Re: [zscript] Changing textures (and more) with zscript

Posted: Sat Mar 24, 2018 9:12 pm
by zrrion the insect
This gets me part of the way there, as it gets me the part where I check the texture. Unsure how to use LineIdIterator though. I also don't really know what I'm doing with TexMan either, but I shouldn't be doing a whole lot with it so that might not impede my progress any.