The Hive Workshop

The Hive Workshop (http://www.hiveworkshop.com/forums/index.php)
-   World Editor Help Zone (http://www.hiveworkshop.com/forums/world-editor-help-zone-98/)
-   -   Basic Introduction to JASS (http://www.hiveworkshop.com/forums/world-editor-help-zone-98/basic-introduction-jass-44835/)

Dezs 12-15-2007 09:25 AM

Basic Introduction to JASS
 
Hmm, so if BJ functions leak, does it mean all of them? When I converted some of the GUI triggers, functions like expirationtimer got a BJ suffix, so those are leaky? If so, then my tower would be a hell of a leak esp since it adds up on every attack. How do I settle this (In simple coding of course)?

Another problem I encourntered after a little thought is regarding the upgrading method I'm using. What I want to create is upgrades that stack on a tower without changing the base unit (simply adding abilities), but I can't figure out a method to perform this smoothly.

I tried using the train unit, but obviously if I remove availability when the ability reaches max, all other towers lose it.

If I use the upgrade method, The icon is messed up sicne it must upgrade into a building of the same type (An upgrade button with the same icon as the tower looks wierd). If I apply a different icon (just to illustrate the upgrade) from the tower's standard, it shows when the player selects multiple towers and looks wierd.

If I use the research method (research, then reset the research to enable research again), I can't remove the research button when the ability reaches cap. Although I can create a trigger to refund and display a message, the research button stays there, which is not so nice.

Dracula 12-15-2007 04:05 PM

yea i tried to learn jass too before, but i dont get what their saying on most of the tuts but that counter strike spell is on youtube.

Need_O2 12-15-2007 04:09 PM

umm DONT USE TUTORIALS :P
find a jass example and learn

Sorry Tutorial Submissionators (english has pwn3d)

aznricepuff 12-16-2007 04:15 AM

First of all, read this: http://www.hiveworkshop.com/forums/s...ad.php?t=16456

It's a great tutorial. I read it when I was first learning JASS and it helped me A LOT. After reading the tutorial I suggest you start making simple custom spells with JASS or open up spell demo maps and looking at the code - that's the fastest way to learn JASS once you know the basics.

Now, as for your questions:
  1. No, you can't do it with GUI (at least not very efficiently if you want multi-instanceability) I'll let Daelin explain the rest here: http://www.hiveworkshop.com/forums/s...ad.php?t=22710 (even includes instructions on how to create a knockback effect with JASS)
  2. Jasscraft (http://www.hiveworkshop.com/resources_new/tools/469/) has a function list for every function in existence in JASS (as well as names for blizzard-coded global variables like bj_lastCreatedUnit and such). The functions are listed with their parameters, what they return, and if they are not natives, what code they contain.
  3. No. I don't know how else you would expect to write JASS without typing it. But don't worry, if you are going into even slightly complex code (like knockback, for example), typing out JASS is actually faster than trying to do it with GUI. And btw, JASS is more similar to C++ than to Java.

Dezs 12-16-2007 05:47 AM

Thanks a lot for the links, but some of the resources are no longer avaiable (well those cna wait for now, i'm still getting the hang of the GUI) at the moment I've tried to get my first custom 'tower' working, but there are some problems around it.

Basically I want to create a Castle that fires multiple arrows from different positions, different firing times to create an arrow shower.

So, at the moment, I created a dummy ability for the upgrade icon on the Castle, a dummy unit that can be trained (renamed as an upgrade) for extra attacks, dummy archers that can attack created on the Castle (small x,y variations).

I'm using a simple trigger that tracks the creation of the dummy upgrade unit to apply the updated icon label, and to remove availability of the unit once it reaches cap level. Up till here the upgrade works fine, but I can't destroy the dummy archers if the Castle dies - I looked up the pick units, and didn't work with units having locust, and the only way I've managed to destroy the dummy archers is with a unit group variable, but its global so if I use that i can only have 1 castle.

How do I change the trigger to be able to record every single instance of a Castle and efefctively preserve the destroy trigger? (I'm still working on GUI, obviously)

Also, is there a setting to make projectiles inaccurate? I think I havent noticed any of those in the object editor.

aznricepuff 12-16-2007 06:29 AM

Jeez, I haven't worked in GUI for that kind of stuff for so long I have NO idea how to do it without JASS lol...

Don't you wish WE supported 2 dimensional arrays?

If you don't mind a little bit of JASS, however, I can give you a system:

In the Custom Scripts section of your map (click on the tft map icon at the very top of your trigger tree), copy-paste these functions:

Jass:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function HandleVars takes nothing returns gamecache
    return InitGameCache( "jasshandlevars.w3v" )
endfunction


function AttachObject takes handle h, string key, handle value returns nothing
    call StoreInteger( HandleVars(), I2S(H2I(h)), key, H2I(value) )
endfunction

function GetAttachedGroup takes handle h, string key returns group
    return GetStoredInteger( HandleVars(), I2S(H2I(h)), key )
    return null
endfunction

function FlushVars takes handle h returns nothing
    call FlushStoredMission( HandleVars(), I2S(H2I(h)) )
endfunction


Then:

Make a trigger detect every time a castle is built (Event - Unit Finishes Construction)

For Actions, put:

Custom Script: local unit castle = GetConstructedStructure()
Custom Script: local group g = CreateGroup()
Custom Script: call AttachObject( castle, "dummygroup", g )
Custom Script: set castle = null
Custom Script: set g = null

Have a trigger detect every time one of your dummy archers is trained (Event-Unit Finishes Training a unit)

For Actions, put:

Custom Script: local unit dummy = GetTrainedUnit()
Custom Script: local unit castle = GetTriggerUnit()
Custom Script: call GroupAddUnit( GetAttachedGroup( castle, "dummygroup" ), dummy )
Custom Script: set dummy = null
Custom Script: set castle = null

Then, have another trigger detect when a castle dies (Event - A unit Dies, Conditions - Unit Type of <Triggering Unit> is equal to...)

For Actions:
Custom Script: local unit castle = GetTriggerUnit()
Custom Script: local group g = GetAttachedGroup( castle, "dummygroup" )
Custom Script: local unit u
Custom Script: loop
Custom Script: set u = FirstOfGroup( g )
Custom Script: exitwhen ( u == null )
Custom Script: call RemoveUnit( u )
Custom Script: call GroupRemoveUnit( g, u )
Custom Script: endloop
Custom Script: call DestroyGroup( g )
Custom Script: call FlushVars( castle )
Custom Script: set castle = null
Custom Script: set g = null

I've basically used what is known as "attached handles" to save dummy archers to the castle that built them. So, when the castle dies, you can easily retrieve the archers assigned to that castle and remove them from the game. If you want to know more about attached handles, read Daelin's advanced JASS tutorial: http://www.hiveworkshop.com/forums/s...ad.php?t=22710 (same link as in my previous post).

One caveat is that what I've given you above will leak. It won't be as bad as leaking special effects or lightning (in other words your game won't start to lag horribly within 2 minutes of building castles) but the leaks will nevertheless be present. The leak issue (and incidentally the problem with 2-dimensional arrays) can be solved using more advanced JASS but since you're a beginner I'm not going to get into that.

If you were wondering its the constant calling of the HandleVars() function that causes the leaks because InitGameCache() leaks every time you call it. But don't worry, it's a very minor issue that should not cause any problems.

Btw, I'm not sure what you mean by "inaccurate projectiles". There's an option on unit attacks to make them not homing so they don't always hit (like with mortar teams and such).

Dezs 12-16-2007 07:06 AM

Okay . . . gimme a while to comprehend that lol . . I've been spending most of the day staring into walls of text here and there, trouble is I find that the tutorials are throwing me pieces from everywhere -.-

In terms of programming concepts, I'm fine with that since I already know C++, so the concepts like leaks, how to make this do that and then do that is not much of a problem. I'm still trying to find a good resource that can apply the JASS language step by step (Well, not to the extent of what is a function -.-) - almost like when you're tkaing up the your first class for Java (Yeah, I remember it sucked, and I still hate Java).

Oh, ya and regarding the inaccurate projectile thingy, what I mean is say like when I was playing around with CnC:Generals, the INI's had inaccuracy built into the units, it had a value called inaccurracy radius or something like that. What it does is to make the attacker inherently inaccurate, not that the projectile can't track, but his hand can't aim straight. Currently, even if the tracking is removed, the tower is still precisely accurate over the rnage of thousands (aiming ahead). So, is there a simple value that can make the unit aim with less precision?

Thanks a lot for the help . . I'll take some time to look around again later -.- Now I need let go of stress a bit -.-

aznricepuff 12-16-2007 07:13 AM

Lol I need to get rid of stress too, but that won't be happening anytime soon....

Well if you know C++ then JASS should be no issue cuz in my opinion JASS is just a dumbed down version of C++. It's just memorizing what function does what and what JASS can and can't do (i guess mostly wut it can't do if you already know C++)

Regarding the inaccuracy, I don't know of any way to make a unit inherently inaccurate.

Dezs 12-16-2007 11:50 PM

ALrite, aftera good nites sleep, I'm ready to ge tback to work again . . anyway I've figured out another solution around it, say:

Train dummy upgrade unit -> Increase ability level -> When castle attack -> Create dummy archer -> Wait -> Remove Dummy Archer -> When castle attack -> .. .

So technically, this allows multiple castles, each being wacthed by the trigger, but my guess is that it would be a very processor intensive thing since every attack we have units spawning and being removed, so I just wanna ask how efficient is this algorithm? I've seen various maps also having like every second events, I'm not sure but these kind of events are also processor intensive right?

Another thing I'd like to clarify is with regard to variables, say I have a global variable I use to temporarily store a point, but I don't nullify it, so there is a leak. However, the next time I use that variable, I replace the value, so tehnically the leak doesn't increase in size, right? I'm not sure about dynamic variables like those in C++, or does it occur whenever we decalre our own locals only, then we have leak problems? I also read that many standard/library functions also leak, so does that mean that the GUI functions provided themselvs are leaking internally?

aznricepuff 12-17-2007 12:15 AM

I'm not sure how processor intensive your new system is. Really the best way to find out is just to test it in-game.

If you don't nullify globals, it's no problem because theres only one variable. It's only with locals where every time the function is called a new local is created and if you don't nullify those variables eventually you have a bunch of local variables using up memory (strings, integers, reals, and booleans don't leak, though).

As for functions, natives usually don't leak, lots of BJ functions (functions with the suffix BJ, like ForGroupBJ) do leak. Not all GUI functions call BJ functions, though most do. BJ functions are also less efficient than natives because all they do is call other natives.

Dezs 12-17-2007 02:55 AM

Oh i see, so these variables don't automatically close after the end of a function. .

About the processing thing, what I mean is comparing towards the solution you provided, that is instead of continously create - destroy vs create then wait till death - remove. I gues what I'm trying to say is whether it is worthwhile -

aznricepuff 12-17-2007 06:14 AM

I really don't know how efficient or inefficient creating/removing units every time castles attack is, but I would guess that my way of just using the attached handle variables is more efficient.

My advice is use my system if you can understand it well enough. If you have no clue how my system works and will spend hours just figuring out how to implement it/tweak it to fit in your map then just go with your idea.

Dezs 12-18-2007 02:17 AM

Hmm, so if BJ functions leak, does it mean all of them? When I converted some of the GUI triggers, functions like expirationtimer got a BJ suffix, so those are leaky? If so, then my tower would be a hell of a leak esp since it adds up on every attack. How do I settle this (In simple coding of course)?

Another problem I encourntered after a little thought is regarding the upgrading method I'm using. What I want to create is upgrades that stack on a tower without changing the base unit (simply adding abilities), but I can't figure out a method to perform this smoothly.

I tried using the train unit, but obviously if I remove availability when the ability reaches max, all other towers lose it.

If I use the upgrade method, The icon is messed up sicne it must upgrade into a building of the same type (An upgrade button with the same icon as the tower looks wierd). If I apply a different icon (just to illustrate the upgrade) from the tower's standard, it shows when the player selects multiple towers and looks wierd.

If I use the research method (research, then reset the research to enable research again), I can't remove the research button when the ability reaches cap. Although I can create a trigger to refund and display a message, the research button stays there, which is not so nice.

aznricepuff 12-18-2007 04:50 AM

Not all BJ functions leak, only some do. But all of them are less efficient than natives because all they do is call natives, and useless repetitive function calls will just slow down your game for nothing.

By the way, just because a function doesn't have a BJ suffix doesn't mean it is a native. Take, for example:

Jass:

function GroupAddUnitSimple takes unit whichUnit, group whichGroup returns nothing
    call GroupAddUnit(whichGroup, whichUnit)
endfunction


GroupAddUnitSimple() is not a native, all it does is take the parameters, flip the order, and call GroupAddUnit(), which is a native. Basically Blizzard uses two functions to do the job of one. Pretty useless...and you can find lots more like these.

Quote:

functions like expirationtimer got a BJ suffix, so those are leaky?
If you are talking about TimerStartBJ(), no the function itself does not leak, but if you don't destroy the timer after you are done with it, it will take up memory.

An example of a leaky non-native would be:

Jass:

function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index

    set index = 0
    loop
        set bj_groupEnumTypeId = unitid
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
        call GroupAddGroup(g, result)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)

    return result
endfunction


If you notice, the local groups g and result are never nullified and so those variables (being handles) will continue to use up memory even after the function closes.

Regarding your tower upgrade problem, I can't think of a system much better than the ones you've already considered.

Dezs 12-18-2007 05:05 AM

Okay, so if I want to clear out the leaks, I'll have to convert them and then add my own codes to clean them up? Or do I have rewrite the entire block (that settles leaks) that the non-native is supposed to do?

Or is it possible to create function overrides for JASS? Then I could write a global function that can be called in place of the non-natives.

I've been looking into the resource pages as well, so is there anything there that is reccomended for me to install? Theres quite a lto of stuff, but I'm trying out WorldEditorUnlimited, LeakCheck, etc

Another thing I realised during my experimentation by creating dummy achers only when the castle attacks is that it interfered with another castle attacking as well (initially I used a wait trigger then proceded to remove last created unit), ending up with units not beign removed. After changing it to use expiration timers, it works fine.

So does this mean that only one instance of the trigger can execute at once and must be finished before it can execute again? Is the trigger limited to track one event and condition (Meaning that say like I upgrade 6 towers simultaneously, only one instance will trigger, not all 6)?


All times are GMT. The time now is 10:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1 PL2
Copyright © Ralle