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
508
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.
  • 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 The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs
  • Monovertex Monovertex:
    @The Helper I'm really not seeing the "Signature" link in the sidebar on that page. Here's a screenshot:
  • The Helper The Helper:
    I have reported it - I was wondering why nobody I have given sigs to over the last few years have used them
  • The Helper The Helper:
    Ghan has said he has fixed this. Monovertex please confirm this fix. This was only a problem with people that had signatures in the upper levels like not the special members but the respected members.
  • The Helper The Helper:
    Here is a better place to manage this stuff https://www.thehelper.net/account/account-details which I think should be way more visible
  • The Helper The Helper:
    I am hoping that online user count drop is finally that TikTok bot banned
  • Ghan Ghan:
    I added the filter last night.
  • The Helper The Helper:
    They are still there

      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