Organizing multiple zscript files

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!)
Post Reply
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Organizing multiple zscript files

Post by Kzer-Za »

I want to sort them into different subfolders to avoid cluttering the main folder. How do I make them load from these subfolders?
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Organizing multiple zscript files

Post by m8f »

Put your files to the directories that you want, and include them in your main zscript lump:

Like this:

Code: Select all

version "3.7.0"

#include "zscript/file1.txt"
#include "zscript/file2.txt"

#include "zscript/lib/libfile1.zsc"
#include "zscript/lib/libfile2.zsc"   
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Organizing multiple zscript files

Post by Kzer-Za »

Thanks!

Does it matter what the included files' names are? For now I left them named "zscript.something", but should "zscript." part be left, or stripped, or it doesn't matter?
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Organizing multiple zscript files

Post by m8f »

The names of the included files don't matter.

The only thing that does matter is the name of the main "zscript" file. Also, It's strongly recommended to make subfolders and/or file names unique, so they won't clash with other mods.
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Organizing multiple zscript files

Post by Kzer-Za »

I went on with organizing the structure and run into a problem: several classes in my zscripts define variables. While they were in the main folder it didn't cause problems, but now that they are in a subfolder and included into the main file, the game won't load with this error:

Code: Select all

:zscript/monster_projectiles/zscript.hl_8_proj_lich, line 181: Attempt to redefine 'hitList'
:zscript/monster_projectiles/zscript.hl_5_proj_beast, line 3:  Original definition is here
:zscript/monster_projectiles/zscript.hl_8_proj_lich, line 257: Attempt to redefine 'hitList'
:zscript/monster_projectiles/zscript.hl_5_proj_beast, line 56:  Original definition is here
The definition is this:

Code: Select all

Class BrutalWereDragonBall : FastProjectile replaces BeastBall
{
	Array<Actor> hitList;
	
	override int SpecialMissileHit (Actor victim)
	{
		if (victim.GetSpecies() == target.GetSpecies())
			return 1;
		if (hitList.Find (victim) == hitList.Size())
		{
			victim.DamageMobj (self, target, 10, 'Fire');
			hitlist.Push (victim);
		}
		A_PlaySound("world/lavasizzle", CHAN_AUTO);
		return 1;
	}
Default
...
For other classes the definition is the same. What should I do about it? Just renaming the variable seems strange since it does the same thing, so giving it different names in different classes would make it more difficult to keep track of things
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Organizing multiple zscript files

Post by Kzer-Za »

Also, why does it first write that the original definition is in the line 3 of zscript.hl_5_proj_beast, then that it's in the line 56? Yes, it is defined in both these lines because it is used in two Weredragon projectiles, but shouldn't the engine in the second error write that the original definition is in the line 3? Because it's there that it's defined first.

And how do you make variables local? (Am I correct that this problem is because this variable is seen as global?) All it says in https://zdoom.org/wiki/ZScript_features is "Local variables (known as user variables in DECORATE)", but not how to define local or global variables.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Organizing multiple zscript files

Post by m8f »

These variables should not clash, indeed. It's hard to understand the problem with only the given snippet. It's an intriguing problem, and if you wish, I can try to debug it, if I have the described ZScript files.
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Organizing multiple zscript files

Post by Kzer-Za »

That would be very kind of you, thanks in advance.

Here they are. Again, there were no problems while they were lying in the main folder, errors aroused when they were moved to a subfolder and included into the main file.
Attachments
projectiles.zip
(3 KiB) Downloaded 21 times
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Organizing multiple zscript files

Post by m8f »

In your code, FirePillarBase class inherits BrutalWereDragonBall class. Note that when you inherit one class from another, it receives all the attributes from the parent.
Then, you define hitList in FirePillarBase, but it is already present (from BrutalWereDragonBall).
So, remove hitList definition from FirePillarBase, and you should be fine. You still can use hitList in FirePillarBase.

The question is why this code did not produce the error in the original form. I think it is a bug, and reported it here.
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Organizing multiple zscript files

Post by Kzer-Za »

Thanks!
Post Reply

Return to “Scripting”