Organizing multiple zscript files

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 a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Organizing multiple zscript files

Re: Organizing multiple zscript files

by Kzer-Za » Fri Feb 15, 2019 7:03 am

Thanks!

Re: Organizing multiple zscript files

by m8f » Fri Feb 15, 2019 6:49 am

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.

Re: Organizing multiple zscript files

by Kzer-Za » Thu Feb 14, 2019 11:32 pm

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

Re: Organizing multiple zscript files

by m8f » Thu Feb 14, 2019 11:17 pm

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.

Re: Organizing multiple zscript files

by Kzer-Za » Thu Feb 14, 2019 10:44 pm

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.

Re: Organizing multiple zscript files

by Kzer-Za » Thu Feb 14, 2019 8:17 am

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

Re: Organizing multiple zscript files

by m8f » Thu Feb 14, 2019 5:45 am

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.

Re: Organizing multiple zscript files

by Kzer-Za » Thu Feb 14, 2019 5:25 am

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?

Re: Organizing multiple zscript files

by m8f » Thu Feb 14, 2019 4:51 am

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"   

Organizing multiple zscript files

by Kzer-Za » Thu Feb 14, 2019 4:32 am

I want to sort them into different subfolders to avoid cluttering the main folder. How do I make them load from these subfolders?

Top