• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Lua] How to make globals throughout script?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

For using LUA scripts, I have to use the blocks like this:
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
...
//! endexternalblock

But how can I make a global variable in one block which exists in all the other separate blocks? Kind of like global variables in JASS--once you declare it, all other triggers can see it.

So basically I'd like to have this

Block of Globals

JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
//My list of global variables
//! endexternalblock

Block of unit objects (separate trigger)

Block of item objects

etc..

All on separate triggers to make code readable (my units object code is already many many pages long >_>, I don't want to put another 10,000 lines of code for items just to use some constants that I calculated from units).
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Each external block is its own script, they all run separately. As such, these scripts can't see each other at all.

My suggestion is to actually write .lua files and then do a //! import into the external block. Alternatively, you can actually run the exes outside of WE. You can pass in the map and everything ;).

The Lua framework I wrote installs scripts on to the machine via other Lua and then runs those scripts with dofile (all within the same block). Check my resources in my sig under the Lua folder.
 
Status
Not open for further replies.
Top