GetRandomStruct

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
What is the best way to do this? e.g.:

JASS:
struct goodid extends pitemtype
    integer BUYid
    integer DISid
    
    static method create takes integer id, integer PUAid, integer BUYid, integer DISid, integer encumbrance returns goodid
        local goodid g=goodid.allocate()
        set g.id=id
        set g.PUAid=PUAid
        set g.BUYid=BUYid
        set g.DISid=DISid
        set g.encumbrance=encumbrance
        return g
    endmethod
endstruct


I want to randomly pick an index of goodid, but, I don't want to pick a null index. Should I just keep trying (random between 1 and 8190) until I get one? That works okay if you have 7104 of them, but if you have 2...

The best solution I can see is to keep track of the max index of goodid. How do I do that?
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
I shouldn't even be posting here, but....

What prevents you from sticking a global in the create method to track the number of structs you've created? (I assume something does since you most likely would have done that if it were possible.)

Could you do something similar to that where you actually call up the struct, but not have it directly inside the struct?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I shouldn't even be posting here, but....

What prevents you from sticking a global in the create method to track the number of structs you've created? (I assume something does since you most likely would have done that if it were possible.)

Could you do something similar to that where you actually call up the struct, but not have it directly inside the struct?

Why would you use globals if you are using structs? :p Just make a struct variable to count. I didn't really read the question, I'm just basing my answer off of what you just said. xD
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
> Why would you use globals if you are using structs?

It sounded more like "count the structs." Why couldn't you use a global to do that? Just an integer.

I need to be educated out of my neanderthal ways. :p
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
What if I have 4000 goodids, and, suddenly, I destroy the first 2000?

If I add a global into the create method (and increment it by 1), then I would logically need to do the opposite in the onDestroy method. But, in the above scenario, I would have 2000 instances. However, they wouldn't be stored under 1-2000. They would be under 2001-4000. That's why I want the max index (4000), not the count (2000). Unless, of course, I am wrong with my thoughts, and vJass shifts everything down when you remove an instance.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
> What if I have 4000 goodids, and, suddenly, I destroy the first 2000?

Depends on how you destroy them, I suppose.
Ideally, you would shift all the other structs down to fill in any holes and adjust your global to compensate.
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
And then, what happens to all of the handles pointing to your struct? They are now pointing to the struct ABOVE the one they should be...
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
> And then, what happens to all of the handles pointing to your struct?

You are determined to defeat me. :p
That's fine. I expected it, actually. :rolleyes:

Shift all of your handles down, too. Or re-create them....
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Perhaps you would like to write me a system which keeps track of every reference I make to a struct, the handle I attach it to, and automatically shifts the references every time a struct is destroyed? Or, would you rather just keep track of the max index?

You may see why I chose the path I did.


Anyway, I think vJass does this anyway, and I just have to know which global it is (or maybe I am once again assuming too much).
 

Cohadar

master of fugue
Reaction score
209
Struct allocation system does NOT shift anything anywhere,
when you destroy a struct it leaves empty space there
XXXX0XXXXXXX0000000000
witch will be filled the next time you create some struct.

Why the hell do you need random structs anyways?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
I was pretty sure that was how it worked.


I need random structs because I am using them to define types (like itemtypeid), and then I have structs which are objects, which you create using the type. Then, there is an item based shop, which sells these types, and is populated with all of the good types every x seconds. You can add staples to the shop, which will ALWAYS show up, and ban types from your store. Right now, I am struggling with only 2 things:

1) Getting a random struct
2) Defining inheritance

You see, I have this:

JASS:
    interface pitemtype
        integer id
        integer PUAid
        integer encumbrance
    endinterface
    
    struct pitemid extends pitemtype
        static method create takes integer id, integer PUAid, integer encumbrance returns pitemid
            local pitemid p=pitemid.allocate()
            set p.id=id
            set p.PUAid=PUAid
            set p.encumbrance=encumbrance
            return p
        endmethod
    endstruct

struct goodid extends pitemtype
    integer BUYid
    integer DISid
    
    static method create takes integer id, integer PUAid, integer BUYid, integer DISid, integer encumbrance returns goodid
        local goodid g=goodid.allocate()
        set g.id=id
        set g.PUAid=PUAid
        set g.BUYid=BUYid
        set g.DISid=DISid
        set g.encumbrance=encumbrance
        return g
    endmethod
endstruct

    struct equipid extends pitemtype
        integer dur
        integer durmax
        
        static method create takes integer id, integer PUAid, integer encumbrance, integer dur, integer durmax returns equipid
            local equipid e=equipid.allocate()
            set e.id=id
            set e.PUAid=PUAid
            set e.encumbrance=encumbrance
            set e.dur=dur
            set e.durmax=durmax
            return e
        endmethod
    endstruct


What I would like is for goodid to be either an equippable or a regular item. Do this, though, create would have to take a pitemtype, which I'm not sure I want to do, as that requires you to define something twice (once for a regular item, and once for the store). I might be ok with it, though, if I make goodid not extend pitemtype... Of course, it would be awesome if I had 2 full arrays for each instance of the shop, so I could define the maxstock and restocktime for each item UNIQUELY for each shop, even if they are selling the same item. It looks though, as if I will need to add those two parameters into the goodid, and make them constant for a single type. You can still simulate the effect by creating two goodid's with the same pitemtype sold, but with different maxstock and restock values, then ban one from a store, and the other from another store.
 

Cohadar

master of fugue
Reaction score
209
Store pitems in a collection,
then make GetRandomPitem function by using Iterator loop on collection

For a more details how look at GroupPickRandomUnit() implementation
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
And this solves my problem because collections DOES move structs down when you remove one, right?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top