• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[LUA]Any ideas on making this more plausible?

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
So... any ideas on how to get this integer I'm making in the Lua script into the JASS without having to do //! import?

This is the code
JASS:
//! textmacro FILE_NAME
    //! i FILE_NAME = "your file name"
//! endtextmacro

//! textmacro OBJECT_CREATOR
    //! i lastCreatedObject = string.char(1, 1, 1, 0)
    //! i function IncObject(s)
    //! i       local i = 5
    //! i       repeat 
    //! i           i = i - 1
    //! i           s = string.sub(s, 1, i-1) .. string.char(string.byte(s, i)+1) .. string.sub(s, i+1)
    //! i       until (string.byte(s, i) < 127 or i == 1)
    //! i       if (string.byte(s, i) == 127) then
    //! i           return nil
    //! i       end
    //! i       return s
    //! i end
    
    //! i function ConvertObjectToInteger(object)
    //! i   return ((string.byte(object, 1)*128+string.byte(object, 2))*128+string.byte(object, 3))*128+string.byte(object, 4)
    //! i end
    
    //! i function WriteObject(object, objectName)
    //! i   local f = io.open("jass\\objectData." .. FILE_NAME .. "." .. objectName, "w+")
    //! i   f:write("globals\n\tconstant integer " .. string.upper(objectName) .. "=" .. ConvertObjectToInteger(object) .."\nendglobals")
    //! i   f:close()
    //! i end
    
    //! i function GetObject(objectName)
                //1 0 0 0 = 2097152
                //SOH NUL NUL NUL
                //start one below so 0 can be used
    //! i       local f = io.open("jass\\objectDataLua." .. FILE_NAME .. "." .. objectName, "r")
    //! i       local createdObject
    //! i       if (f == nil) then
    //! i           createdObject = IncObject(lastCreatedObject)
    //! i           local t = { "units", "items", "destructables", "doodads", "abilities", "buffs", "upgrades" }
    //! i           local i = 0
    //! i           local b = 7
    //! i           local e = true
    //! i           repeat
    //! i               i = i + 1
    //! i               if (i > 7) then
    //! i                   i = 1
    //! i               end
    //! i               setobjecttype(t[i])
    //! i               e = false
    //! i               while (objectexists(createdObject)) do
    //! i                   if (not e) then
    //! i                       e = true
    //! i                       b = b + 1
    //! i                       if (b > 7) then
    //! i                           b = 1
    //! i                       end
    //! i                   end
    //! i                   createdObject = IncObject(createdObject)
    //! i                   if (createdObject == nil) then
    //! i                       return nil
    //! i                   end
    //! i               end
    //! i           until (i == b and not e)
    //! i           f = io.open("jass\\objectDataLua." .. FILE_NAME .. "." .. objectName, "w")
    //! i           f:write(createdObject)
    //! i           f:close()
    //! i           WriteObject(createdObject, objectName)
    //! i       else
    //! i           createdObject = f:read()
    //! i           f:close()
	//! i       end
    //! i       return createdObject
    //! i   end
//! endtextmacro

And this is a script using it
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro FILE_NAME()
    //! runtextmacro OBJECT_CREATOR()
    //! i local object = GetObject("MY_OBJECT")
    
    //! i setobjecttype("abilities")
    //! i createobject("Adef", object)
    //! i makechange(current, "anam", "Unit Indexing")
    //! i makechange(current, "ansf", "(Unit Indexing")
    //! i makechange(current, "aart", "")
    //! i makechange(current, "arac", 0)
//! endexternalblock

I'd like to be able to somehow import the file I'm making up above rather than doing this-
//! import "objectData.your file name.MY_OBJECT"

Any thoughts? : D
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
Um what?

As far as I know there is no way to run LUA in un modified WC3 as it only axcepts and runs JASS code from various scripts starting when the map loads.

If you mean...
How do I get this LUA script to generate a line of JASS code setting an integer to a value generated in the script?

Then I would imagine running the script outside the editor in a program which executes LUA code and pasting the generated line into the map.

If this is some wakky feature some one has added to a third party or moded editor to let you do on save computation of data via LUA, then I advise contacting the author or reading the documentation as LUA is not part of WC3, WE or even JNGP (a popular WE enhacner) last time I knew.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
JassHelper added an externalblock to use and execute LUA code inside the editor. Good morning, DSG. :D

Yea, if you run my above code in WE, it will work.. You just have to save, close the map, then reopen it, comment out the lua, and uncomment the import.

I want it to be able to import it immediately ; (.

This script would be soooo very useful as it would ensure unique object ids for systems that create objects, like j4l's BuffStruct or dummy units or w/e else. I want to use this script for an update to evo/devo unit to use chaos >: D.
 
Status
Not open for further replies.
Top