HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass Structure Return Type

09-28-2007, 06:16 PM#1
Strilanc
Two issues within hours of each other.

This time I have a method which gives off a compile error when I say it returns type S (but works fine with return integer). To make things even more confusing, other method which return type S work fine.

The structure is just a wrapper for the timer class. A bit silly, but I like to do things like this.

Collapse JASS:
struct S
  ...
  public static method getExpiredTimer takes nothing returns S //<== compile error: type S not defined
    local integer i
    local timer t = GetExpiredTimer()

    set i = 1
    loop
      exitwhen i > S.numAllocated
      if (S.timers[i].t == t) then
        return S.timers[i]
      endif
      set i = i + 1
    endloop

    return nill //nill is a constant integer = 0
  endmethod
  ...
  public static method create takes nothing returns S //<=== no error
  ...
  public static method fine takes nothing returns S //<=== no error
  ...
endstruct

It looks like, for some reason, "Timer" isn't being changed to "integer". I have no idea what that reason is.
09-28-2007, 06:30 PM#2
Vexorian
you are going to have to post more code...

I am not sure why that method has to return S at all though.
09-28-2007, 06:37 PM#3
Strilanc
I looked for awhile, then decided it was probably an error in the compiler.

Downloaded the latest newgen, and now it works.

(It returns type S because I want the S that contains the timer which fired)
09-28-2007, 06:39 PM#4
Vexorian
what version of jasshelper were you using?
09-28-2007, 10:29 PM#5
Strilanc
3d

I'm now having different issues with 3g. When I have a static method being "executed", the first argument loses its type declaration in the script.

Collapse JASS:
struct S
  static method E takes integer i returns nothing //<== Compile error: undefined type i (script is missing "integer")
     //^==Changing to non-static fixes compile error
     ...
     call TriggerSleepAction(...)
     ...
  endmethod
  static method C takes nothing returns nothing
    call S.E.execute(1) //<=== changing to S.E(1) fixes compile error
  endmethod
endstruct

and my workaround, since S is never instantiated in this case:
Collapse JASS:
struct S
  method E takes integer i returns nothing
     ...
    call TriggerSleepAction(...)
    ...
  endmethod
  static method C takes nothing returns nothing
    local S temp = nill //0
    call temp.E.execute(1)
  endmethod
endstruct

Now, I don't know if there is some reason for not allowing static methods to be executed; but such a simple workaround suggests it isn't required.
09-28-2007, 10:55 PM#6
Vexorian
did it actually work in "3d" ?
09-28-2007, 11:09 PM#7
Strilanc
Quote:
Originally Posted by Vexorian
did it actually work in "3d" ?

I don't know, but I doubt it. I rarely ever use .execute
09-28-2007, 11:22 PM#8
Vexorian
I guess it didn't work, cause I never considered static methods for execute, guess it is something to add later.