[zscript] Changing textures (and more) with zscript

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

[zscript] Changing textures (and more) with zscript

Post 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.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

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

Post 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.
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

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

Post 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.

Return to “Scripting”