• 🏆 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] Importing global variables

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

So suppose I have two separate Lua scripts, A and B.

Script A generates a series of item abilities and then stores their raw code ids in an array, call it IDS.

Script B generates a series of items whose item ability is based on the abilities generated in script A.

This means:

Code:
for i = 0, TOTAL_ITEMS do
  set items[i].itemAbility == IDS[i]
endfor

Which basically says that for each item in script B, there is a corresponding item ability in script A (or vice versa).

I would like to keep my code modular and separate item objects from abillity objects. Which means script A and script B are necessarily disjoint (different files).

Is there anyway I can "simulate" the code in script A and then somehow import the IDS array? When I say simulate, I mean perform the computations of the script without actually doing anything else (e.g. actually generating the objects).

My plan was to simply parse a script file and copy down its variables. But this doesn't work if the variable is not static (e.g. its final value changes over the computations of the script).

So if I can't import from a Lua object generation file, can I somehow do some I/O on its variables, e.g. print all the variables to some text file, which I can then read to do my pseudo-import?
 
So if I can't import from a Lua object generation file, can I somehow do some I/O on its variables, e.g. print all the variables to some text file, which I can then read to do my pseudo-import?

Hm. iirc, you can use print() on the variables (assuming we're talking about lua), and then get the output file in the logs folder. Or one of those text files, I don't remember which...
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
I was hoping this would exist.

Do I just do print(variableName) ? And it will go to some pre-determined text file?

But how can I run that without actually making the objects (i.e. the "simulation" I mentioned)?
 
Status
Not open for further replies.
Top