Structs in JASS AI?

Status
Not open for further replies.
Level 2
Joined
Jan 3, 2021
Messages
6
Hi there : )

TLDR at the end.
I'm currently trying to write a campaign AI and as you might imagine, it's not working. I have the following line at the beginning of the main function to get some semblance of feedback:

JASS:
call DisplayTextToPlayer(Player(22),0,0,"AI started")

When this line shows the file works. Doesn't mean the AI does what I want it to, but at least the file has no critical errors. But the line doesn't show...
I tried removing and pasting the code back in piece by piece to find the error. As soon as the struct I wrote is in the file I no longer see the message in game. I posted the struct below and you'll see it isn't exactly complex.

JASS:
struct Attackwave
    integer array unittypes[ATTACKWAVEMAXUNITTYPES]
    integer array unitamounts[ATTACKWAVEMAXUNITTYPES]
    integer currentIndex
     
    static method create takes nothing returns Attackwave
        local Attackwave new = Attackwave.allocate()
        set new.currentIndex = 0       
        return new
    endmethod
    
    method addUnit takes integer unitType, integer amount returns nothing
        if this.currentIndex <= (ATTACKWAVEMAXUNITTYPES - 1) then
            set this.unittypes[this.currentIndex] = unitType  
            set this.unitamounts[this.currentIndex] = amount
            set this.currentIndex = this.currentIndex + 1
        endif  
    endmethod
endstruct

Now, while there is a definite possibility that there's just an error in the struct, I went over it again and again without finding anything. So, I figured it is possible that structs aren't usable in JASS AI files. I couldn't find any structs in the common.ai. Can I not use Structs in .ai files, or more general vJASS?

TLDR; Can I not use Structs in .ai files?
 
Hi there : )

TLDR at the end.
I'm currently trying to write a campaign AI and as you might imagine, it's not working. I have the following line at the beginning of the main function to get some semblance of feedback:

JASS:
call DisplayTextToPlayer(Player(22),0,0,"AI started")

When this line shows the file works. Doesn't mean the AI does what I want it to, but at least the file has no critical errors. But the line doesn't show...
I tried removing and pasting the code back in piece by piece to find the error. As soon as the struct I wrote is in the file I no longer see the message in game. I posted the struct below and you'll see it isn't exactly complex.

JASS:
struct Attackwave
    integer array unittypes[ATTACKWAVEMAXUNITTYPES]
    integer array unitamounts[ATTACKWAVEMAXUNITTYPES]
    integer currentIndex
    
    static method create takes nothing returns Attackwave
        local Attackwave new = Attackwave.allocate()
        set new.currentIndex = 0      
        return new
    endmethod
   
    method addUnit takes integer unitType, integer amount returns nothing
        if this.currentIndex <= (ATTACKWAVEMAXUNITTYPES - 1) then
            set this.unittypes[this.currentIndex] = unitType 
            set this.unitamounts[this.currentIndex] = amount
            set this.currentIndex = this.currentIndex + 1
        endif 
    endmethod
endstruct

Now, while there is a definite possibility that there's just an error in the struct, I went over it again and again without finding anything. So, I figured it is possible that structs aren't usable in JASS AI files. I couldn't find any structs in the common.ai. Can I not use Structs in .ai files, or more general vJASS?

TLDR; Can I not use Structs in .ai files?
No, structs and other vJass syntax needs to first be compiled to JASS before it can be used in AI files.
 
Level 2
Joined
Jan 3, 2021
Messages
6
No, structs and other vJass syntax needs to first be compiled to JASS before it can be used in AI files.
Thank you for the answer! : )
As far as I'm aware, JassHelper does just that, right? This post would suggest that at least, among others. JassHelper is now integrated with the WE and has a seperate folder in the install location, as far as I'm aware. However, I can't really figure out how to use it. Most resources concerning the use of the JassHelper reference the site wc3c which no longer exists. There was a manual hosted there. I also couldn't find anything useful in the tutorial section. Do you maybe have a link or two where I could read up/learn about how to use the JassHelper to compile vJass to Jass?

My scrappy go at getting what I want:
The WE shows you a seperate window where it shows the code JassHelper compiled, but only when you have a compile error. So I tried to be smart about it and put an error on prupose after my struct. I then saved to see the compiled code for the struct, which unfortunately just kinda worked. Based on this post there you be a lot more code in the empty jasshelper__initstructs...

JASS:
//JASSHelper struct globals:
constant integer si__Attackwave=1
integer si__Attackwave_F=0
integer si__Attackwave_I=0
integer array si__Attackwave_V
integer array s___Attackwave_unittypes
constant integer s___Attackwave_unittypes_size=10
integer array s__Attackwave_unittypes
integer array s___Attackwave_unitamounts
constant integer s___Attackwave_unitamounts_size=10
integer array s__Attackwave_unitamounts
integer array s__Attackwave_currentIndex

endglobals


//Generated allocator of Attackwave
function s__Attackwave__allocate takes nothing returns integer
 local integer this=si__Attackwave_F
    if (this!=0) then
        set si__Attackwave_F=si__Attackwave_V[this]
    else
        set si__Attackwave_I=si__Attackwave_I+1
        set this=si__Attackwave_I
    endif
    if (this>818) then
        return 0
    endif
    set s__Attackwave_unittypes[this]=(this-1)*10
    set s__Attackwave_unitamounts[this]=(this-1)*10
    set si__Attackwave_V[this]=-1
 return this
endfunction

//Generated destructor of Attackwave
function s__Attackwave_deallocate takes integer this returns nothing
    if this==null then
        return
    elseif (si__Attackwave_V[this]!=-1) then
        return
    endif
    set si__Attackwave_V[this]=si__Attackwave_F
    set si__Attackwave_F=this
endfunction

//custom script
function s__Attackwave_create takes nothing returns integer
    local integer new= s__Attackwave__allocate()
    set s__Attackwave_currentIndex[new]=0
    return new
endfunction

function s__Attackwave_addUnit takes integer this,integer unitType,integer amount returns nothing
    if s__Attackwave_currentIndex[this] <= ( ATTACKWAVEMAXUNITTYPES - 1 ) then
        set s___Attackwave_unittypes[s__Attackwave_unittypes[this]+s__Attackwave_currentIndex[this]]=unitType
        set s___Attackwave_unitamounts[s__Attackwave_unitamounts[this]+s__Attackwave_currentIndex[this]]=amount
        set s__Attackwave_currentIndex[this]=s__Attackwave_currentIndex[this] + 1
    endif
endfunction

//Struct method generated initializers/callers:
function jasshelper__initstructs1077750437 takes nothing returns nothing




endfunction

This doesn't seem right to me. Is there a way to just see the compiled code without having an error? Anyway, any help on finding resources for the proper use of JassHelper would be appreciated :hohum:
 
Status
Not open for further replies.
Top