HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Confusing.

06-13-2008, 02:38 AM#1
Feroc1ty
Just a quick vJass question.

Are structs same things ass C++ classes or structs? Because I think I have seen methods in structs, and I just believe that the syntax should be renamed to class instead of struct.

Bah, I figured it out, you can put methods in it, just confused why would it be named struct instead of class. Because of this, I am going to create a few classes, I was wondering if they would be of any use but easier programming.

Collapse JASS:
struct Unit
    private real x = 0
    private real y = 0
    private real health = null
    private real mana = null
    private real face = 0
    private integer unitid = 'hpea'
    unit module = CreateUnit(0, 'hpea', 0, 0, 0)

    method GetX takes nothing returns real
        return this.x
    endmethod
    
    method GetY takes nothing returns real
        return this.y
    endmethod
    
    method SetX takes real tx returns nothing
        SetUnitX(this.module, tx)
    endmethod
    
    method SetY takes real ty returns nothing
        SetUnitY(this.module, ty)
    endmethod
    
    method GetFace takes nothing returns real
        return this.face
    endmethod
    
    method GetHealth takes nothing returns real
        return this.health
    endmethod
    
    method GetMana takes nothing returns real
        return this.mana
    endmethod
    
    method SetHealth takes real health returns nothing
        SetUnitState(this.module, UNIT_STATE_LIFE, health)
    endmethod
    
    method SetMana takes real mana returns nothing
        SetUnitState(this.module, UNIT_STATE_MANA, mana)
    endmethod
    
    method ResetUnitId takes integer unitid returns nothing
        RemoveUnit(this.module)
        this.module = CreateUnit(0, unitid, this.x, this.y, this.face)
    endmethod
endstruct

I was wondering why I am getting this error, it's probably a dumb mistake that I can't see myself, but someone point it out for me :).

Line 81: Syntax Error.
Quote:
this.module = CreateUnit(0, unitid, this.x, this.y, this.face)
06-13-2008, 03:55 AM#2
Vexorian
You are programming in Jass, not C, not Java, not C++, not pascal. Take a quick look at your code and notice the two basic Jass keywords you are missing.

structs are not classes (thank god) of course, they allow methods and other extravagant stuff like interfaces and the extends operator, but they aren't classes.

Quote:
unit module = CreateUnit(0, 'hpea', 0, 0, 0)
I know it compiles and works and all, but I think I will consider that murder from now on...
06-13-2008, 04:00 AM#3
Here-b-Trollz
Or if cryptic messages aren't your style, remember that almost every line in Jass starts with either set or call, depending if you are assigning a value to a variable or calling a function, respectively.

The issue is not with vJass.
06-13-2008, 04:06 AM#4
Feroc1ty
I really think that as us, programmer, need to adapt to the new computers, wasting a little memory or performance doesn't matter that much these days, computers are getting better every day, but making the job easier indeed helps a lot. By the way, I was wondering why would you "I will consider that murder from now on..."
06-13-2008, 04:32 AM#5
Here-b-Trollz
Such a thing is better off in a create method than an allocate method.
06-13-2008, 07:03 AM#6
Strilanc
Quote:
Originally Posted by Jokes-On-You
I really think that as us, programmer, need to adapt to the new computers, wasting a little memory or performance doesn't matter that much these days, computers are getting better every day, but making the job easier indeed helps a lot. By the way, I was wondering why would you "I will consider that murder from now on..."

Right, let's just keep negating all those hardware advances with crappy code. That will make life easier. I mean, bubble sort isn't *that* much worse, right?
06-13-2008, 03:59 PM#7
Squally425
Classes and structs are used interchangeably in C++. They both serve different functions. Although in C++, people mainly use classes, in C (that C++ derived from obviously.. C + 1) structs were used.

Since at this stage, I'd call vJASS a fairly structured form of programming (rather than object oriented), I'd say struct appears to be the better name for it =)
06-13-2008, 04:06 PM#8
Fireeye
For the compile error
Code:
native          CreateUnit              takes player id, integer unitid, real x, real y, real face returns unit
and you're passing 0 as player which is invalid due it's an integer not a player, use Player(0) instead.