Correct syntax method operators []

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
It's been so long since I've vJassed, I've forgotten what the correct syntax was of this. I know the basic idea, but how would I write the method operator for something like this?

score would be the method operators name.

[lJASS]call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, I2S( u.score[PLAYER_SCORE_FOOD_MAXUSED] ) )[/lJASS]
 

Jesus4Lyf

Good Idea™
Reaction score
397
I don't think it is that simple -

You may define [] for a struct type, and you may define it for instances of that type. You may not define name[] (as far as I know). So what you must have for u.score[] is a struct "u" with a member which is also a struct named "score", with a non-static operator.

So:
JASS:
method operator [] takes handle h returns IHaveNoIdea
    return Something[GetHandleId(h)]
endmethod

You must figure out what you wish to store and how.

I bet that wasn't what you were after. Please tell us exactly what you are trying to do, and reveal your "u" and "score" structs, or whatever you have.
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
You're right, a better example is required but I thought I could name method operators which take [], but anyways here is a better example.
JASS:
struct user extends array
    player p
    // Something like this I had in mind:
    method operator score[] takes playerscore whichPlayerScore returns integer
        return GetPlayerScore( .p, whichPlayerScore )
    endmethod
endstruct

// Somewhere later..

call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, I2S( user(0).score[PLAYER_SCORE_FOOD_MAXUSED] ) )


So, what you're saying is the only way this is possible is having a struct, withing user named score and add a method operator to that.

Edit:
I hope this isn't the only way, of which I am willing to conciser that is.
 

Jesus4Lyf

Good Idea™
Reaction score
397
For teh lulz, try this:
JASS:
struct ScoreDummy
    method operator score[] takes playerscore whichPlayerScore returns integer
        return GetPlayerScore( Player(this) /* faster than array read - see Azlier */, whichPlayerScore )
    endmethod
endstruct

struct user extends array
    // Assuming Player(user[x])==Player(x)
    method operator score takes nothing returns ScoreDummy
        return ScoreDummy(this)
    endmethod
endstruct

I think that will inline... depends on order or parameters in struct methods. <_<
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I've been looking for something just like this as well. I figured out how to do it the way Jesus4Lyf described, but I just decided to exchange [ljass] u.score[PLAYER_SCORE_FOOD_MAXUSED][/ljass] (the nonexistent syntax "method operator score[]")with [ljass] u.score(PLAYER_SCORE_FOOD_MAXUSED)[/ljass] (the syntax "method score").

It's a very subtle difference, and while it may look a bit strange, I think it's the easiest way to fix it.
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
JASS:
    method operator score[] takes playerscore whichPlayerScore returns integer

    /* faster than array read - see Azlier */

Syntax error, ofcourse :p. Either way, when I changed it to [], the u.score[MAX_FOOD...] gave a syntax error. In other words, no dice.
And for that inline comment, what the hell is going on here. I thank you for the update but this is just ridiculous, seriously.
Could you perhaps link me to the post?

I've been looking for something just like this as well. I figured out how to do it the way Jesus4Lyf described, but I just decided to exchange [ljass] u.score[PLAYER_SCORE_FOOD_MAXUSED][/ljass] (the nonexistent syntax "method operator score[]")with [ljass] u.score(PLAYER_SCORE_FOOD_MAXUSED)[/ljass] (the syntax "method score").

It's a very subtle difference, and while it may look a bit strange, I think it's the easiest way to fix it.
This really breaks my heart. I've quit mapping for a long time, came back for just messing around and I come to the conclusion that this is a non existent syntax?!
Your fix kinda defeats the purpose, of it being a function instead of acting as a variable array.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
This really breaks my heart. I've quit mapping for a long time, came back for just messing around and I come to the conclusion that this is a non existent syntax?!
Your fix kinda defeats the purpose, of it being a function instead of acting as a variable array.

I know what you mean, I became pretty disappointed with method operators when I learned how limited they are. I know the fix defeats the purpose of using array-like syntax, but after all it is a function whether you were to write it with [] syntax or () syntax.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>And for that inline comment, what the hell is going on here. I thank you for the update but this is just ridiculous, seriously.
>Could you perhaps link me to the post?

I agree and don't care for speed advantage. In fact, it is apparently circumstancial. I just was hoping you weren't doing the .p thing for a speed advantage. :)

Link. Have a read of the thread... *Shrugs*
 

Azlier

Old World Ghost
Reaction score
461
>Have a read of the thread... *Shrugs*

The fact that my benchmark was a mess, that the array was faster 70% (thus proving that the benchmark is garbage) of the time, and that we need a better benchmark are the results from that thread.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top