ZScript Translation Property in Functions

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
Post Reply
User avatar
MrYossarian
Posts: 11
Joined: Wed Jan 24, 2018 4:46 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Not in the US
Contact:

ZScript Translation Property in Functions

Post by MrYossarian »

So, I've been trying to mess around with the translation property in ZScript.
I'm essentially trying to change the translation of an actor through a function, but, I can't seem to get it working as a string.

Here's an example:

Code: Select all

class TranslationTest : ZombieMan
{
	override void BeginPlay()
	{
		if(target.player)
		{
			let player = target.player;
			Color col = player.GetColor();
			Translation = String.Format("0:255=#[%i,%i,%i]", col.r, col.g, col.b);
		}
	}
}
When I try to test that out, GZDoom doesn't launch and says that Translation is expecting a numeric result, which I don't understand because I can perfectly do it in the Default block, but I can't put strings in functions. When looking at the Translation property, it seems to be a uint type. So, is there a way to convert this string into a uint or something?
I can put numbers for the translation, but not a string, so, I don't know what to do here.

Any help would be appreciated.
Thank you!
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: ZScript Translation Property in Functions

Post by Cherno »

I would assume that similar to StateLabels, Translations are internally stored as integers, so they can't be passed as local variables during runtime. Try to define a translation via TRNSLATE and pass its name instead. I could be wrong, though.
User avatar
MrYossarian
Posts: 11
Joined: Wed Jan 24, 2018 4:46 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Not in the US
Contact:

Re: ZScript Translation Property in Functions

Post by MrYossarian »

So, basically, I can't dynamically change the translation of the actor? The translation has to be hard coded?
Well, that's a shame. I think I can do it through ACS though, so I think I'll go with that, I just would have hoped that I could do it through ZScript.

Thanks for your help though.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: ZScript Translation Property in Functions

Post by Arctangent »

You can absolutely change the translation of an actor. You just can't change it to a translation that hasn't already been defined.

Think of how strings work in ACS - you can swap them out with each other just fine through ACS, but if you try to pass a string in an ACS_Execute call from DECORATE or ZScript? You don't get the expected results. This is because strings variables ( and, really, every variable type ) in ACS are actually just integers, with functions that use strings using them as indices for an internal string table. Compiling strings in ACS adds them to that table, but trying to pass a string to a script does not.

It's the same deal with translations. You can define two different translations strings on two different actor classes, then have one copy the translation variable of another at run-time and it'll work just fine. The reason that works, but passing a new translation string doesn't, is because the translation strings in the actors' properties have already been compiled and converted to indices in the translation table, and that's what's stored in the translation variable. So when you copy another actor's translation variable, you're swapping it to another entry in the table, and that entry has a translation sequence that's already been processed.

The long and short of it is that you are very possibly overengineering what you want to do, because if you can keep the colors you want to translate consistent between player and non-player actor, all you have to do is Translation = target.Translation.
User avatar
MrYossarian
Posts: 11
Joined: Wed Jan 24, 2018 4:46 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Not in the US
Contact:

Re: ZScript Translation Property in Functions

Post by MrYossarian »

Ah yeah, then clearly I won't be able to do it unfortunately as the translation is not consistent between the player and the non-player actor.

The translation needs to be blended, which means the actor would have the hue of the player's color, mainly the player that's being targeted by the actor in this example.
I just don't think I can define a translation during gameplay through ZScript, I can do it through ACS though, as I managed to successfully do that.

Anyway, I just think that what I'm trying to do in ZScript is just not supported atm, hopefully a feature like this can be added soon instead of having to pass through ACS to dynamically create translations.
Post Reply

Return to “Scripting”