• 0

    posted a message on Java Question

    I'm still pretty new to java and I'm trying to learn how to open url's through script. From what I understand, two of the ways to do this are:

    1. 1. Directly use URL.getContent()
    2. 2. Creating a URLConnection object, then using it to open the connection and subsequently, an input stream from which you can read the information.

    The question is, in what scenario would the latter be better than the prior? My first impressions are that method 1 would obviously be much faster (I'm guessing it's the equivalent of a GET command when we attempt to retrieve content via the browser.

    Also, if I were to open a connection object to say, www.google.com, is there a way for me to open input streams based on extra url information:

    Example www.google.com/herp/derp/hello.html, where the string in bold is dynamic,

    without having to close the existing connection object? If so, how is this done?

    +Will I experience memory leaks if I don't properly destroy objects that are no longer used? Or does Java handle that automatically?

    Posted in: Off-Topic
  • 0

    posted a message on Do you consider yourself part of an organized religion?

    Christian (baptism at birth), Free thinker by choice. I lost my faith in prayer/religion due to the fact that mine have never been answered when I needed them most. My stance is that I believe in the individual. I believe that we can achieve great things if we put forth the necessary effort.

    Posted in: Off-Topic
  • 0

    posted a message on Using Array Variables

    @sethmachine: Go

    Not sure what the question is there, but a better way would be to use records (structs) as they allow you to declare properties of different types.

    It's declared as such in script, I don't know how it's done in GUI as I don't use it.

    struct hero{
       int[6] stats;
    };
    hero[6] struct_hero;
    

    When you want to callback the stats, just refer to the struct: struct_hero[ hero_index ].stats[stat_index]

    PS: I forgot to mention this in my earlier post, its actually a way you could pull off what you're trying to do as it is similar to an array in an array.

    Posted in: Triggers
  • 0

    posted a message on Using Array Variables

    @sethmachine: Go

    int Array[3][3] a

    Yeah, that's how they work. I usually avoid them like the plague though, as they can get very hard to keep track of.

    Posted in: Triggers
  • 0

    posted a message on Using Array Variables

    @sethmachine: Go

    contains a single element (Array[0])
    This. Arrays are 0 indexed. So an array of size 1, starts at index 0.

    Array[0] = IntArray{0,1,2} Array[1] = IntArray{5,112,79} Array[2] = IntArray{10000, 99584, 6543} etc...

    Don't think there's a way to do this without a workaround, since we don't have pointers in galaxy. The closest solution I can think of to this is to store the numbers in a comma delimited string "0,1,2", then write a function to extract specific elements from it.

    Posted in: Triggers
  • 0

    posted a message on Possible to change unit stat via triggers?

    @Aaternus: Go

    I just checked the wiki, from the description I think I'm mistaken. Catalogs allow you to change on a player by player basis, not a unit by unit basis. Yaksman's answer I believe should be correct, as I do recall using such a function to mod unit stats before.

    Posted in: Triggers
  • 0

    posted a message on Possible to change unit stat via triggers?

    Try look up catalogs. I believe they allow you to set unity stats on a unit by unit basis. There is a limitation though, not all stats can be modified

    Posted in: Triggers
  • 0

    posted a message on Thread maximum

    @Mille25: Go

    I rest my case for now, It's 4 am, need sleep. Thanks for the discussion, you've made some excellent points that I do not currently have a counter-argument to.

    Most likely id say there is no difference between both methods, until someone gives me a clear test that proves the opposite.
    I'll post a response to this if I'm able to find some conclusive evidence.

    Thought I'd share what looks to be an interesting read though: Trigger Mechanics

    Although the author states its relatively theory, it's very detailed explanation, and the guy seems to know his stuff. I plan to have a detailed read myself when I've the time, as it might resolve some of the doubts we've had during our debate.

    Edit: Section 7 in the link explains very clearly what I was trying to explain earlier. I was slightly mistaken on the way triggers are handled though. There is actually a scheduler and a trigger queue which controls trigger execution. When the queue gets to long, that's when we start to experience lag

    Posted in: Triggers
  • 0

    posted a message on Thread maximum

    @Mille25: Go

    So whats your point?

    My point, is that I believe events do not perform as well as a while loop with waits on the processor and memory (RAM) level. Each event that fires, opens a new thread (Every trigger is run on a separate thread). The more threads we have running in parallel, the more your processor core is going to distribute its processing power. Evidence of this happening is the OP's post, in which a claim was made whereby he had a lot of periodic events.

    So how do you get to that conclusion?

    Based on my understanding of how Triggers work on the process and memory (RAM) level. 1 Event firing = 1 Trigger queued into your RAM, which the processor will in turn process in it's own thread. Lets say for example, we have 20 periodic events with the smallest time step possible. That's 20 / 0.0625 = 320 threads being created in the span of 1 second.

    So what happens when each of these threads takes longer than 0.0625 seconds to execute? The processors load gets constantly divided. As this occurs, each thread begins to take longer and longer to run (Because of the distributed load). This, in conclusion, is the root cause of the lag experienced from the user's perspective.

    This does not happen with the alternative, a trigger with a while loop, because it only queues a single thread into the processor. The less threads there are, the less the processors load is divided, thus resulting in better performance.

    Hope that made sense.

    PS: One might argue that a workaround to this is to simply not have such a short time step between periodic events. My counter-argument:

    1. Sure, but it also means the frequency that the trigger can run is restricted.
    2. I believe it is not a good coding practice in the long run, especially as a project continues to grow in script/memory usage size
    Posted in: Triggers
  • 0

    posted a message on Thread maximum
    Quote from Mille25: Go

    @FuzzYD:

    Source?

    First hand encounter with a periodic event causing severe lag in one of my projects. After I switched it to a while loop, the lag magically disappeared. It's only apparent when testing with the debugger on, as it shows your process. With a periodic event that uses the smallest possible time step (0.0625s), the debugger screen gets flooded with events firing, and within a minute SC2 complains that I need to lower my graphics setting. With the while loop approach, this doesn't happen.

    With the debugger off, the lag isn't obvious, but background process wise, it is taking up more of the process because of the event handler firing rapidly. Map attached as proof. Just disable the 'PeriodTest' and enable 'WhileTest' to do the comparison. Also, make sure to turn on the debugger to see the difference.

    Posted in: Triggers
  • 0

    posted a message on Thread maximum

    If it's possible in Gui, use a while loop with a wait. It's much better than a periodic event firing every x seconds. The way events are handled is very process intensive

    Posted in: Triggers
  • 0

    posted a message on Galaxy++ editor

    @elunder: Go

    Believe you're out of luck on this one :/ That's a no. Its something they've overlooked IMO.

    Note: If you're working on g+ +, ignore my answer, I'm referring to the vanilla galaxy code.

    Posted in: Third Party Tools
  • 0

    posted a message on Why do you map?

    I just enjoy the process of coming up with optimal solutions to a given programming problem. I also find that there's a lot of interesting things to discover about the editor, and there's always one way or another one can further their knowledge of it.

    Posted in: Off-Topic
  • 0

    posted a message on Custom Buttons

    @sethmachine: Go

    Assuming you have photoshop.

    1. Export the asset from the editor
    2. Open it in photoshop and copy it.
    3. Create a new file and set the color settings to Grayscale, then paste the copied image.
    4. Cut the grayscale image and paste it back on a new file with RGB color settings.
    5. Attach a layer mask with the overlay 'Hue' and change the color to red.
    6. Export the result using a .dds exporter. You can also use .tga files, be sure to save the alpha channels, or you will lose your transparency
    Posted in: Artist Tavern
  • 0

    posted a message on Creating sets/memberships

    @sethmachine: Go

    I actually envisioned it's use in a slightly different way. Rather than checking each set for specific unit types, associate each unit type with a set, and directly call it back. Create the user type ("Sets") to have just 1 field, "Species"

    Create your instances to have the ID as the name of the unit "Dog" (instead of an integer as in the tutorial), with the species column "Canine"

    When your unit dies, simply user UnitGetType, to retrieve the unit type (Dog) as a string, and use it as your instance.

    Then just use UserDataGetString("Sets", "Dog", "Species", 1). Whereby 1 denotes the first value

    This should return "Canine"

    //Event
    Unit dies
    //Variables
    unit u = EventUnit();
    string ud = "Sets";
    string instance = UnitGetType(u);
    string species =  UnitDataGetString(ud, instance, "Species", 1);
    

    Note: User type instances are all strings.

    I haven't been able to find a function that returns a boolean like "UnitIsInstanceOfUserType(unit type, unit)"

    I need to look this up when I have access to my editor. If you wish to do it this way, I'm not sure if there's a function that allows it, but I'll help you check (It's not documented in the wiki yet, and I can't find it online).

    Edit: I think there might be a function to check if a user type has a specific instance. If so, you could do, UserTypeHasInstance(UserType, Instance), and have it set up how you envisioned it. Just use the unit type as the instance name, and you have a direct mapping

    Just checked the new function list: http://us.battle.net/sc2/en/forum/topic/5825622546

    There's no function to check if a user type has an instance, but there is a workaround you can use.

    Create your usertype with 1 integer field. This field will act as a boolean flag (0 or 1). Lets call it IsSet.

    • Set your default instance to have IsSet = 0.
    • Create new instances with the unit types as your ID, and IsSet = 1

    So your user type instances should look something like this:

    1. 0, [Default], 0
    2. 1, Dog, 1

    Your trigger should be something like this

    //Events
    Unit dies
    //Vars
    unit u = EventUnit();
    string ud = "Canines";
    string instance = UnitGetType();
    int IsSet = UserDataGetInt(ud, instance, "IsSet", 1)
    
    if (IsSet == 1){
        Display the message "Unit is a user type"
    }
    

    What we expect to happen here is that, if an instance does not exist within a user type definition, it will return the default instance value, which is 0 (False).

    UserDataGetInt("Canine", "Tiger", "IsSet", 1)
    

    Should thus, return 0 (False)

    You probably want to create a secondary user type with the titles of all your species and the mineral reward information. Loop through the instances of the secondary user type, to check the sets 1 by one.

    If this is not clear, please give me the weekend, I'll script an example map for you.

    Posted in: Triggers
  • To post a comment, please or register a new account.