• 🏆 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!

[vJASS] Why doesn't this library see my struct?

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

I've got two libraries. The first uses a textmacro to generate variations of a struct. The second then uses of those variations in some code.

I have the second library require the first, but even so jasshelper complains that the struct doesn't exist at all.

JASS:
library Structs

//! textmacro takes Type
struct $Type$Struct
  integer i = 0
  static method create takes nothing returns thistype
    set thistype this = thistype.allocate()
    return this
  endmethod
endstruct
//! endtextmacro

//! runtextmacro("A")
endlibrary

Now my second library

JASS:
library Test requires Structs

function foo takes nothing returns nothing
  local AStruct s = AStruct.create() //complains about this line
  set s.i = 5 //complains here too
endfunction

endlibrary

I searched the generated map script and it didn't seem to even generate my AStruct code at all. Why is this not working?
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
Why is this not working?

Because your library Structs itself is already full of errors:

JASS:
library Structs

// textmacros must have a name
//! textmacro takes Type
struct $Type$Struct
  integer i = 0
  static method create takes nothing returns thistype
    // what is "this"? you have to declare it first before you can set it
    set thistype this = thistype.allocate()
    return this
  endmethod
endstruct
//! endtextmacro

// Running a textmacro requires its name
//! runtextmacro("A")
endlibrary

->

JASS:
library Structs
	//! textmacro MY_MACRO takes Type
	struct $Type$Struct
		integer i = 0
		static method create takes nothing returns thistype
			local thistype this = thistype.allocate()
			return this
		endmethod
	endstruct
	//! endtextmacro

	//! runtextmacro MY_MACRO("A")
endlibrary

library Test requires Structs
	function foo takes nothing returns nothing
		local AStruct s = AStruct.create() // Works now
		set s.i = 5
	endfunction
endlibrary
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
You could also use UPPER_CASE for textmacro args, it's easier to catch where the possible changes might go.

Whatmore, if you planing to implement varienty of structs (possibly part of API) it's good to add ACCESS parameter and write it before struct declaration:
$ACCESS$ struct $NAME$Struct extends array. Control is everything :)
 
Status
Not open for further replies.
Top