vJass readonly keyword doesn't work for array members

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Can someone confirm this, or am I "missing" something

I use the following script to test:
JASS:

struct S
    readonly integer array ARRAY[12]
    readonly integer NOT_ARRAY
endstruct

function main takes nothing returns nothing
    local S s = S.create()
    set s.ARRAY[11] = 5
    set s.NOT_ARRAY = 5 // jasshelper gives error on this line instead of the above :/
endfunction
 

Dirac

22710180
Reaction score
147
Well maybe because youre using a non-static array it bugs.
Don't use non-static arrays
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I am getting strange stuff now:

JASS:
struct S
    readonly static integer array ARRAY[12] // [12] is not needed
endstruct

function main takes nothing returns nothing
    local S v = S.create()
    set v.ARRAY[0] = 0 // compiles to: set s__s__S_ARRAY[0]= 0, but should give error, not just because it's readonly but also because it's a static member right?
    set S.ARRAY[1] = 1 // cimpiles to: set s__s__S_ARRAY[1]= 1
endfunction
 

Laiev

Hey Listen!!
Reaction score
188
>>but also because it's a static member right?

No, only if it was [ljass]constant[/ljass].
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I think in other programming/scripting languages that have some oo features allow static members to be referenced only by
the class/struct's name but not by instance variables, I guess vJass is an exception.

class C { static integer si = 0 }
...
C.si = 4; // works as expected
C c = <get C instace>
c.si = 1; // doesn't work as expected
...
 

krainert

Member
Reaction score
10
I think in other programming/scripting languages that have some oo features allow static members to be referenced only by
the class/struct's name but not by instance variables, I guess vJass is an exception.
Code:
class C { static integer si = 0 }
...
C.si = 4; // works as expected
C c = <get C instace>
c.si = 1; // doesn't work as expected
...

Java supports accessing class members through objects as well as classes, but relying on the former is discouraged.
http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

C#, on the other hand, supports accessing class members through classes only.
http://msdn.microsoft.com/en-us/library/79b3xss3.aspx
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
krainert is absolutely right, even C++ seams to allow instance variables to access static member varaibles, so this means that vJass is not the exception =)
although, it's still a "bad" practice in my opinion.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top