JASS and vJASS questions thread

For discussions regarding skinning and mapmaking for Warcraft 3.

Moderator: Moderators

JASS and vJASS questions thread

Postby Drain_Pipe » Wed Jul 08, 2009 5:09 pm

Ok so I'm once again getting back into JASS but ever since my comp got fucked up everything was at a standstill. BUT now I want to get back into it. I know some of the basic stuff but what i really want to know is setting up things the JASS way and making stuff MUI. so I now have questions for that sort of thing.

1. What do i need in order to use vJASS? I used to have the stuff but now its been awhile and I forget.

2. Should I even bother with JASS at all, or head straight to vJASS?

3. How can I set up a function to be able to call itself (ie in terms of a knockback system where 1 unit being knocked back knocks back another.)

4. How do I setup periodic events?

5. What are some key things about JASS (ie syntax or debugging) that are common problems to look for when a code doesn't work properly?


That's all i got for now, thanks in advance for any help. BTW I'd rather explanation rather than chunks of code whenever possible or both.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Wed Jul 08, 2009 6:19 pm

1. To use vJass, you need Jasshelper. It is most commonly used with JassNewGenPack, which you can get here. The newest JassHelper version can be found here. (Note: the newest jasshelper is probably not included with newgen right now ..., you will have to download it seperately and replace the files)

2. You should probably head straight to vJass. The simple aspects of it pretty much just help your code be cleaner, and easier to write. You should probably learn the basics of structs / libraries & scopes / function interfaces while learning Jass. It's really all you ever use in most cases.

3. Normally a knockback system is coded using a stack of structs, looped through on the expiration of a single timer... So all you have to do is add another struct to the stack. I use something like this for allocation / deallocation: (ex from projectile system thing)

Code: Select all
//Members of struct
    //Id of projectile in stack
    private        integer          projId

    //Static values -> timer and stack of projectiles
    private static Projectile array projectiles
    private static integer          projNum = 0

// ... later on

method allocate takes nothing returns nothing // These might as well be inlined
        set .projNum = .projNum + 1
        set .projectiles[.projNum] = this
        set .projId = .projNum
endmethod

method deallocate takes nothing returns nothing
        if .projId < .projNum then // Don't bother moving the last one to it's own slot.
            // Move top projectile to slot of removed
            set .projectiles[.projId] = .projectiles[.projNum]
            set .projectiles[.projId].projId = .projId
        endif
        set .projNum = .projNum - 1
endmethod



4. Periodic events are usually setup using the type 'timer'. These run a function (every / after) x seconds, with the only usable callback being 'GetExpiredTimer()' -- if you want to store something to the timer, think about Timer Utils Red. An example :

Code: Select all
scope DamageOverTimeEX initializer init

globals
    //Configurable constants....
    private constant integer Rawcode = 'A000' //inlined anyway
    private constant real INTERVAL = 0.25
endglobals

//Configurable values based on level -> hero abilities mainly
private constant function Duration takes integer level returns real //inlined anyway
    return 5. //Constant
endfunction

private constant function Damage takes integer level returns real //inlined anyway
    return 10. + 5. * level
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Rawcode
endfunction

private struct Data // A struct is just a bunch of arrays, in a nice simple format
    unit caster
    unit target
    real duration
    integer level
endstruct

private function Loop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Data dat = Data( GetTimerData( t ) ) //Timer utils function -> get the stored integer... (typecast the integer to struct)
   
    call UnitDamageTarget( dat.caster, dat.target, Damage( dat.level ), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null )
                        //You should probably get a damage detection system and replace this ...
                       
    set dat.duration = dat.duration - INTERVAL
    if dat.duration <= 0. then
        call ReleaseTimer( t ) // Timer utils function -> release timer, (will also pause)
        call dat.destroy() // Release struct
    endif
endfunction

private function Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
   
    local timer t = NewTimer() //Timer utils function -> replacing CreateTimer()
    local Data dat = Data.create() //Allocate a struct
   
    local integer level = GetUnitAbilityLevel( caster, Rawcode )
   
    set dat.caster = caster
    set dat.target = target
    set dat.duration = Duration( level )
    set dat.level = level
   
    call SetTimerData( t, integer( dat ) ) //Timer utils function -> store integer to the timer (typecast struct to integer... don't have to do this)
    call TimerStart( t, INTERVAL, true, function Loop )
   
    set caster = null
    set target = null
    // Do not have to null timer, it is recycled
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) // This could be replaced by it's contents inlined
                                                                            // Or a similair function you make yourself, it
                                                                            // Doesn't really matter, as it is only run once
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction
endscope


5. Forgetting to initialize variables ( usually for counted loops ), forgetting to attach a struct to a timer, ... It really varies depending on the problem
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Cassiel » Wed Jul 08, 2009 6:28 pm

This is really better suited to WC3C.

1. The easiest way to use JassHelper (which is the vJASS compiler) is through NewGen.

2. vJASS is still JASS. It compiles to JASS and can't do anything that JASS doesn't also do. vJASS just makes everything much more efficient in terms of workflow. For example, you can declare globals wherever you want, automatically turn functions into triggers and treat them as objects with function interfaces, etc.

3. JASS doesn't support recursive functions, but it doesn't need to for what you're talking about. Dusk's Knockback System does what you want. The best way to learn is to study what's already been made.

4. There is never a reason to use periodic events. Usually when someone says "never" what they really mean is "rarely," but in the case of periodic events never means never. Use a timer instead.

5. That depends on you. One thing you'll find with JassHelper is that the syntax checker is vastly better than what you're used to. The majority of the time it will be able to tell you exactly what your mistake is.

There are lots of tutorials at places like WC3C, TheHelper and TheHive.

http://www.wc3c.net/showthread.php?t=91491
http://www.wc3c.net/showthread.php?t=103408
http://www.wc3c.net/showthread.php?t=100953
http://www.thehelper.net/forums/showthread.php?t=125565
http://www.thehelper.net/forums/showthread.php?t=120697
http://www.thehelper.net/forums/showthread.php?t=63595
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Wed Jul 08, 2009 6:45 pm

thanks a bunch.

As for periodic, I already use repeating timers, I just don't use the proper wording :/.

More questions:

1) I've made some abilities and they're probably terribly inefficient, but they seem to run just fine on my own comp. However, some tend to slow down when in online play. Why is this?

2) also, could someone expand on structs, libraries and all that jazz.

3) what are macros and all that other crazy stuff I sometimes see people working on? It doesn't resemble JASS at all :S
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Wed Jul 08, 2009 8:37 pm

1. It could be that you're using the gui "wait x seconds" function (TriggerSleepAction). This is a very messed up function that does run slower online.

2. I'll give you a simple rundown

libraries and scopes:

These are used for 2 purposes
1) To sort the code in the map
2) To make the code cleaner, without interfering (private/public functions)

The sorting is done like this:

At very bottom: code not in scopes / libraries
Above that is scopes, randomly placed (not sorted)
Above that are libraries, which are ordered depending on which "include/need" other ones.

The syntax for a library is this:

Code: Select all
library Example

// All your code goes here

private function foo takes nothing returns nothing // This function can only be used from inside this library
endfunction

function bar takes nothing returns nothing // This function can be used normally anywhere
endfunction

public function foobar takes nothing returns nothing // This function if used outside the library needs to be called by Example_foobar()
endfunction

endlibrary


There is also an optional "initializer <name>" that you can put on the end, for initializing triggers (normally), or other stuffz

Code: Select all
library Example initializer init

function disp takes nothing returns nothing
 call BJDebugMsg("EX")
endfunction

private function init takes nothing returns nothing
 // this is run at map initialization
call disp()
endfunction


Example of using "needs"
Code: Select all
library Example2 initializer init needs Example

pirvate function init takes nothing returns nothing
call disp()
endfunction



A scope is the same thing without being able to use "needs", as it can already use any library ...


Now, for structs:

A struct is really a bunch of arrays, with the index used for them stored as the struct (it is actually just an integer). You define them simply by doing the following:

struct <name>
<type> <name>
<type> <name>
//...
endstruct

for example

struct loc
real x
real y
endstruct

// ...

local loc l = loc.create()
set l.x = 5
set l.y = 5
call BJDebugMsg("X: " + R2S(l.x ) )
call BJDebugMsg("Y: " + R2S(l.y ) )
call l.destroy()

^ this is a pointless usage for example, but you could look at the damage over time spell example from my last post, for a better usage

3. Text macros are simply a way to generate code quickly ... ( you dont really need how to use them for now ) . an example:

//! textmacro TX takes DUMMY, FACE
call MoveLocation( TempLoc, x, y )
set z = GetUnitFlyHeight( .self ) + GetLocationZ( TempLoc )

set tx = x + 500 * Cos( $FACE$ )
set ty = y + 500 * Sin( $FACE$ )

call MoveLocation( TempLoc, tx, ty )
set tz = z - GetLocationZ( TempLoc ) + ZOFFSET

call SetUnitX( $DUMMY$.lookAt, tx )
call SetUnitY( $DUMMY$.lookAt, ty )
call SetUnitFlyHeight( $DUMMY$.lookAt, tz, 0. )
//! endtextmacro

if i wrote //! runtextmacro TX( ".dummy", "a" )

it would replace the //! runtextmacro line with this:

call MoveLocation( TempLoc, x, y )
set z = GetUnitFlyHeight( .self ) + GetLocationZ( TempLoc )

set tx = x + 500 * Cos( a )
set ty = y + 500 * Sin( a )

call MoveLocation( TempLoc, tx, ty )
set tz = z - GetLocationZ( TempLoc ) + ZOFFSET

call SetUnitX( .dummy.lookAt, tx )
call SetUnitY( .dummy.lookAt, ty )
call SetUnitFlyHeight( .dummy.lookAt, tz, 0. )
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Wed Jul 08, 2009 9:18 pm

so text macros make the map run faster?
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Kaz » Wed Jul 08, 2009 10:12 pm

No, they save you a lot of copy/paste
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Thu Jul 09, 2009 5:47 pm

so in theory I could make the same quality stuff as TOB without using text macros and only vJASS? (assuming I had the same modelling ability as chriz and could make my own custom animated models)

on a side note, when i was watching the rat video of TFD, i noticed how unitsd launched into the air went all crazy and spinny and the like. Is that an effect like tornado, or a dummy model or what?
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Thu Jul 09, 2009 9:29 pm

Textmacros don't change the quality of the code / what can be made. They only make it more readable (in very few cases, but don't use them often)

The units getting hit into the air are spun like that by setting their alpha to 0, creating a dummy model with that unit's model attached to them, then setting its pitch ( either a pitch dummy, or head lock dummy )
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Thu Jul 09, 2009 10:31 pm

Only thing I don't get then is wouldn't the unit appear invisible when you select it? I don't think it can be as easy as that.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby nooK » Fri Jul 10, 2009 12:18 am

I thought they are abusing that tornado model.
nooK
 
Posts: 84
Joined: Fri Aug 11, 2006 6:38 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Fri Jul 10, 2009 12:43 am

Well you wouldn't be able to select the dummy unit, but the portrait on the alpha'd guy would probably be invis. Cass told me that's what they do in a pm
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Fri Jul 10, 2009 6:03 pm

couldn't they re size the model to the smallest size instead of chancing the alpha to 0? It will be like being invis, though you can select them and they won't be 100% transparent.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Fri Jul 10, 2009 6:49 pm

0 Scale would work too, they will probably change it to that after finishing their object data program or w/e
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Cassiel » Fri Jul 10, 2009 7:00 pm

Drain_Pipe wrote:couldn't they re size the model to the smallest size instead of chancing the alpha to 0? It will be like being invis, though you can select them and they won't be 100% transparent.

Have you tried selecting a scaled down unit hidden beneath a normal sized one?
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Fri Jul 10, 2009 8:01 pm

I'll test that right now: indeed it seems difficult to directly select them. How about we combine the 2? I just did some fiddling around and you could make the intended unit small, then make a clear dummy unit who is selectable for selection, and then if a player selects the unit, make them add the main unit to selection, and killoff/remove the dummy unit at the same time. The reason for this is that there seems to be no graphical delay if you kill the selected unit, rather than simply remove them from selection. Just a thought either way and it might prove a bigger waste of time on your part but it could work out that way. I just figure a unit going invis on selection while the spell was in effect would look kinda weird. You could also simply remove the dummy from selection but there is that short interval graphical delay. Dunno if anyone would notice.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Bobo_The_Kodo » Sat Jul 11, 2009 12:11 am

That is very messy and selection changes through code isn't instant ...
It works fine like it is, a portrait dissapearing for like a second won't harm anyone :)
Bobo_The_Kodo
 
Posts: 11
Joined: Sun Aug 17, 2008 11:31 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Sat Jul 11, 2009 4:23 pm

no but what i said, the killing method, doesn't show any flaws in it. Try it out, there's virtually no lag time.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Wed Jul 29, 2009 10:29 pm

I'm getting some problems with trying to implement the timer utils red. I literally just copied the text and pasted it into the appropriately titled trigger (ver. 1.23+) and a bunch of errors popped up when saving. Did I miss some other code that's required here or what?
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Cassiel » Wed Jul 29, 2009 10:31 pm

I don't use TimerUtils so I don't know. Are you sure it hasn't been updated for 1.23b/1.24? Did you post in the TimerUtils thread?
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Re: JASS and vJASS questions thread

Postby Fledermaus » Thu Jul 30, 2009 12:07 am

You need the latest patch for the latest version(s) of TimerUtils, hence the name " Red Timer utils ( patch 1.23b or later)". It still has the "Patch 1.23 or earlier" versions in the thread but they wont work if you are patched to anything above 1.23 (duh).
ImageImageImageImage
Image
User avatar
Fledermaus
 
Posts: 557
Joined: Fri Jul 14, 2006 6:02 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Thu Jul 30, 2009 9:06 am

Well I just installed all the components for the latest Newgen pack yesterday and put it in its own folder. Also, I tried both versions of the timer utils and both had problems. Honestly, it might be easier to just come up with my own method for tracking timers.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Cassiel » Thu Jul 30, 2009 9:14 am

There are four versions of TimerUtils in that thread. Red and Blue for 1.23b+, and Red and Blue for pre-1.23b. You can't use the 1.23b+ versions if you haven't updated to 1.23b. NewGen has nothing to do with it. NewGen is a development tool. It does not log onto Battle.net and update WC3 for you.
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Re: JASS and vJASS questions thread

Postby Drain_Pipe » Thu Jul 30, 2009 10:04 am

Well as far as i know I've got the most updated patch for wc3. But, last time I installed the newgen pack, i had to get an older version of the we or something like that for it to run properly. I just checked now, and the version I have using all the additional bonus stuff is version 1.21b.

btw where do i get 1.23b, because right now I just have 1.23 and I've logged onto bnet without getting the update.

on another note, does the newgen pack work with v 1.23? As far as I know, it should... I think.
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: JASS and vJASS questions thread

Postby Cassiel » Thu Jul 30, 2009 10:07 am

Westfall dude. It's a beta.
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Next

Return to Custom Mapmaking

Who is online

Users browsing this forum: No registered users and 1 guest

cron