Organizing multiple zscript files

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.

Organizing multiple zscript files

Postby Kzer-Za » Thu Feb 14, 2019 5: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?
Kzer-Za
 
Joined: 20 Aug 2017

Re: Organizing multiple zscript files

Postby m8f » Thu Feb 14, 2019 5:51 am

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

Like this:
Code: Select allExpand view
version "3.7.0"

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

#include "zscript/lib/libfile1.zsc"
#include "zscript/lib/libfile2.zsc"   
User avatar
m8f
 
 
 
Joined: 29 Dec 2017

Re: Organizing multiple zscript files

Postby Kzer-Za » Thu Feb 14, 2019 6: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?
Kzer-Za
 
Joined: 20 Aug 2017

Re: Organizing multiple zscript files

Postby m8f » Thu Feb 14, 2019 6: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.
User avatar
m8f
 
 
 
Joined: 29 Dec 2017

Re: Organizing multiple zscript files

Postby Kzer-Za » Thu Feb 14, 2019 9: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 allExpand view
: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 allExpand view
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
 
Joined: 20 Aug 2017

Re: Organizing multiple zscript files

Postby Kzer-Za » Thu Feb 14, 2019 11: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.
Kzer-Za
 
Joined: 20 Aug 2017

Re: Organizing multiple zscript files

Postby m8f » Fri Feb 15, 2019 12:17 am

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.
User avatar
m8f
 
 
 
Joined: 29 Dec 2017

Re: Organizing multiple zscript files

Postby Kzer-Za » Fri Feb 15, 2019 12:32 am

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 2 times
Kzer-Za
 
Joined: 20 Aug 2017

Re: Organizing multiple zscript files

Postby m8f » Fri Feb 15, 2019 7: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.
User avatar
m8f
 
 
 
Joined: 29 Dec 2017

Re: Organizing multiple zscript files

Postby Kzer-Za » Fri Feb 15, 2019 8:03 am

Thanks!
Kzer-Za
 
Joined: 20 Aug 2017


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest