HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Can anyone help me with vJass

05-02-2008, 02:16 AM#1
Feroc1ty
Hey it's me Jokes-On-You but now renamed as Feroc1ty, I used to jass script a long time ago, but now as I've come to today's scripting, vJass is the new standart, and I was wondering if anyone could help me convert my script step by step to teach me how to make the Global Variables, Structs, and Etc...

Collapse JASS:
//////////////////////////////////////////////////////// Jokes-On-You's Maze Maker /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Kill takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > udg_players
        if GetTerrainType(GetUnitX(udg_Unit[i]),GetUnitY(udg_Unit[i])) == udg_terrain then
            call KillUnit( udg_Unit[i] )
        endif
        set i = i + 1
    endloop
endfunction

function Slide takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > udg_players
        if GetTerrainType(GetUnitX(udg_Unit[i]),GetUnitY(udg_Unit[i])) == udg_terrain2 then
            call SetUnitPosition( udg_Unit[i], GetLocationX( GetUnitLoc(udg_Unit[i]) ) + 12 * Cos( GetUnitFacing(udg_Unit[i]) * bj_DEGTORAD), GetLocationY( GetUnitLoc(udg_Unit[i]) ) + 12 * Sin( GetUnitFacing(udg_Unit[i]) * bj_DEGTORAD) )
        endif
        set i = i + 1
    endloop
endfunction

function Slow takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i > udg_players
        if GetTerrainType(GetUnitX(udg_Unit[i]),GetUnitY(udg_Unit[i])) == udg_terrain3 then
            call SetUnitMoveSpeed( udg_Unit[i], ( GetUnitDefaultMoveSpeed(udg_Unit[i]) * 0.75 ) )
        else
            call SetUnitMoveSpeed( udg_Unit[i], GetUnitDefaultMoveSpeed(udg_Unit[i]) )
        endif
        set i = i + 1
    endloop
endfunction

function Revive takes nothing returns nothing
    local integer food = 0
    local integer i = 1
    loop
        exitwhen i > udg_players
        set food = food + GetPlayerState(ConvertedPlayer(i), PLAYER_STATE_RESOURCE_FOOD_USED)
        set i = i + 1
    endloop
    if food == 0 then
        if udg_chances != 0 then
            set i = 1
            set udg_chances = udg_chances - 1
            call DisplayTextToForce( GetPlayersAll(), ( "You have " + ( I2S(udg_chances) + " chances left!" ) ) )
            call PolledWait( 2 )
            loop
                exitwhen i > udg_players
                call ReviveHeroLoc( udg_Unit[i], GetRandomLocInRect(udg_respawn), true )
                call PanCameraToTimedLocForPlayer( ConvertedPlayer(i), GetRandomLocInRect(udg_respawn), 1.00 )
                call SelectUnitForPlayerSingle( udg_Unit[i], ConvertedPlayer(i) )
                set i = i + 1
            endloop
        else
            set i = 1
            call DisplayTextToForce( GetPlayersAll(), ( "You have failed!" ) )
            call CinematicFilterGenericBJ( 5.00, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 100, 0, 0, 0, 0 )
            call PolledWait( 5.00 )
            loop
                exitwhen i > udg_players
                call CustomVictoryBJ( ConvertedPlayer(1), false, false )
                set i = i + 1
            endloop
        endif
    endif
endfunction

function initialization takes boolean slide,boolean slow returns nothing
    local integer i = 1
    local timer a = CreateTimer()
    local timer b = CreateTimer()
    local timer c = CreateTimer()
    call TimerStart( a, 0.22, true, function Kill)
    if slide == true then
        call TimerStart( b, 0.03, true, function Slide)
    else
        call DestroyTimer(b)
    endif
    if slow == true then
        call TimerStart( c, 0.38, true, function Slow)
    else
        call DestroyTimer(c)
    endif
    loop
        exitwhen i > udg_players
        if GetPlayerSlotState(ConvertedPlayer(i)) == PLAYER_SLOT_STATE_PLAYING then
            call CreateNUnitsAtLoc( 1, udg_unitt, ConvertedPlayer(i), GetRandomLocInRect(udg_respawn), GetRandomInt(1, 360) )
            set udg_Unit[i] = GetLastCreatedUnit()
        endif
        set i = i + 1
    endloop
    set a = null
    set b = null
    set c = null
endfunction

I will highly appreciate anyone's help, and it will be my pleasure to help you in any kind of way that I could help you.
05-02-2008, 03:15 AM#2
burningice95
Converting to VJASS just for the sake of converting to VJASS is kind of pointless, imho. If you have a working, non-lagging script, why do you need to convert it. VJASS gets converted back to normal JASS anyway, so its not like you are automatically making your script better by turning it into VJASS.
05-02-2008, 04:15 AM#3
Feroc1ty
Well I think that by making the script more efficient it would run faster, and also I just want to learn structs just for the sake of learning, because the only two tutorials I've read on vjass confuse me, and I can't learn it.
05-02-2008, 04:26 AM#4
Ammorth
vJass might not be more effecient than normal jass (since if you know what you are doing, you can simulate anything vJass does). vJass just makes code easier by implementing objects (aka Structs) and allowing free global declaration.
05-02-2008, 04:31 AM#5
Feroc1ty
Well could you teach me not using my script than, because I'm very interested :O.
05-02-2008, 04:39 AM#6
Vexorian
Quote:
Originally Posted by burningice95
Converting to VJASS just for the sake of converting to VJASS is kind of pointless, imho. If you have a working, non-lagging script, why do you need to convert it. VJASS gets converted back to normal JASS anyway, so its not like you are automatically making your script better by turning it into VJASS.
It is easy to assume that since vJass is converted to normal Jass, you can do all what vJass does in normal Jass. However, this assumption is incorrect.
05-02-2008, 09:05 PM#7
Feroc1ty
Quote:
Originally Posted by Vexorian
It is easy to assume that since vJass is converted to normal Jass, you can do all what vJass does in normal Jass. However, this assumption is incorrect.

Well thats another reason I want to learn vJass than...
05-03-2008, 04:23 AM#8
burningice95
Quote:
Originally Posted by Vexorian
It is easy to assume that since vJass is converted to normal Jass, you can do all what vJass does in normal Jass. However, this assumption is incorrect.

Of course not. If that was possible we wouldn't need vJass. I was just using that do demonstrate that if you're spell already works in normal Jass, there is no point in remaking it in vJass (just for the sake of it)
05-03-2008, 04:26 AM#9
Feroc1ty
The point is to implement new features to the system.
05-03-2008, 05:53 AM#10
The Elite
Quote:
Originally Posted by Vexorian
It is easy to assume that since vJass is converted to normal Jass, you can do all what vJass does in normal Jass. However, this assumption is incorrect.
how so?
05-03-2008, 06:49 AM#11
darkwulfv
vJASS doesn't automatically equal faster, better, script with more features and sex. While it can sometimes, there's no point in turning script that works fine into vJASS unless

A: You're submitting it.
B: The script is massive and vJASS could clean it up
C: You need to transfer data between timer functions (Structs are good for this)
D: You like free globals.

Otherwise, vJASS isn't really needed in regular map script. Yes, it has functions and abilities and stuff that are very helpful, but many times its really only needed if you're submitting a map and want the easiest possible way for people to add the code to the map.

Oh, and libraries are pretty helpful too.

The only thing I can see vJASS doing for your script is you making those functions private in a scope, since they have really generic names and would be easy to overlap (assuming you did at some point). Otherwise, there's no need.
05-03-2008, 06:04 PM#12
Feroc1ty
Okay well...

1. I'm thinking of submitting it.
2. The script does use timers.
3. I like free globals.
4. As you mentioned I could convert it into a library.

Well since no one would help I'll just read many tutorials and learn on the way I guess, anyways I started converting the script into vJass, any suggestions would greatly help, here is what I got so far.

Collapse JASS:
globals
    integer chances = 5
    unit array Unit
endglobals

struct int
    real slowpercent = 0.75
    integer players = 10
    integer chances = 5
    rect respawn = gg_rct_spawn
endstruct

function GetKill takes integer i returns boolean
    return GetTerrainType(GetUnitX(Unit[i]),GetUnitY(Unit[i])) == 'Lgrd'
endfunction

function GetSlide takes integer i returns boolean
    return GetTerrainType(GetUnitX(Unit[i]),GetUnitY(Unit[i])) == 'Lrok'
endfunction

function GetSlow takes integer i returns boolean
    return GetTerrainType(GetUnitX(Unit[i]),GetUnitY(Unit[i])) == 'Ldro'
endfunction

function Kill takes nothing returns nothing
    local int in = int.create()
    local integer i = 0
    loop
        exitwhen i > in.players
        if GetKill(i) then
            call KillUnit( Unit[i] )
        endif
        set i = i + 1
    endloop
    call in.destroy()
endfunction

function Slide takes nothing returns nothing
    local int in = int.create()
    local integer i = 0
    loop
        exitwhen i > in.players
        if GetSlide(i) then
            call SetUnitPosition( Unit[i], GetLocationX( GetUnitLoc(Unit[i]) ) + 12 * Cos( GetUnitFacing(Unit[i]) * bj_DEGTORAD), GetLocationY( GetUnitLoc(Unit[i]) ) + 12 * Sin( GetUnitFacing(Unit[i]) * bj_DEGTORAD) )
        endif
        set i = i + 1
    endloop
    call in.destroy()
endfunction

function Slow takes nothing returns nothing
    local int in = int.create()
    local integer i = 0
    loop
        exitwhen i > in.players
        if GetSlow(i) then
            call SetUnitMoveSpeed( Unit[i], ( GetUnitDefaultMoveSpeed(Unit[i]) * in.slowpercent ) )
        else
            call SetUnitMoveSpeed( Unit[i], GetUnitDefaultMoveSpeed(Unit[i]) )
        endif
        set i = i + 1
    endloop
    call in.destroy()
endfunction

function Revive takes nothing returns nothing
    local int in = int.create()
    local integer food = 0
    local integer i = 0
    loop
        exitwhen i > in.players
        set food = food + GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_FOOD_USED)
        set i = i + 1
    endloop
    if food == 0 then
        if chances != 0 then
            set i = 0
            set chances = chances - 1
            call DisplayTextToForce( GetPlayersAll(), ( "You have " + ( I2S(chances) + " chances left!" ) ) )
            call PolledWait( 2 )
            loop
                exitwhen i > in.players
                call ReviveHeroLoc( Unit[i], GetRandomLocInRect(in.respawn), true )
                call PanCameraToTimedLocForPlayer( Player(i), GetRandomLocInRect(in.respawn), 1.00 )
                call SelectUnitForPlayerSingle( Unit[i], Player(i) )
                set i = i + 1
            endloop
        else
            set i = 0
            call DisplayTextToForce( GetPlayersAll(), ( "You have failed!" ) )
            call CinematicFilterGenericBJ( 5.00, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 100, 0, 0, 0, 0 )
            call PolledWait( 5.00 )
            loop
                exitwhen i > in.players
                call CustomVictoryBJ( Player(1), false, false )
                set i = i + 1
            endloop
        endif
    endif
    call in.destroy()
endfunction

function initialization takes boolean slide,boolean slow returns nothing
    local int in = int.create()
    local integer i = 0
    local timer a = CreateTimer()
    local timer b = CreateTimer()
    local timer c = CreateTimer()
    call TimerStart( a, 0.22, true, function Kill)
    if slide == true then
        call TimerStart( b, 0.03, true, function Slide)
    else
        call DestroyTimer(b)
    endif
    if slow == true then
        call TimerStart( c, 0.38, true, function Slow)
    else
        call DestroyTimer(c)
    endif
    loop
        exitwhen i > in.players
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            call CreateNUnitsAtLoc( 1, 'Hmkg', Player(i), GetRandomLocInRect(in.respawn), GetRandomInt(1, 360) )
            set Unit[i] = GetLastCreatedUnit()
        endif
        set i = i + 1
    endloop
    set a = null
    set b = null
    set c = null
    call in.destroy()
endfunction
05-04-2008, 06:05 PM#13
burningice95
A couple of things:

-If you are submitting it, you should make it more easy to configure. Just make everything a constant global, so it will get inlined. These should be configurable (some you already have)
-type of terrain used for slide/kill/ect
-the hero given (you used mountain king)
-Rect used for respawning
-# of players (very important)
-# of chances

-Pause timers before you destroy them

-function slide leaks a location (just stick with SetUnitX and SetUnitY, instead of SetUnitPosition)

-In function slow you use the unit's default movement speed. But what if the maze maker wants their hero to have items? You should use current movement speed instead, or an ability.
05-05-2008, 12:29 AM#14
Feroc1ty
I don't quite get it, before people would try to avoid globals at all cost, but now that you can declare a global anywhere its a great new thing?

Is it better to use a global or a struct?

And I don't see where I leak a location.

EDIT: nvm, found it dumb mistake, don't see why I didnt use GetUnitX,Y in the first place, would have removed some typing too.
05-05-2008, 12:39 AM#15
darkwulfv
Originally, globals were clunky and ugly. They were a pain to transfer and had to be made in the Variable editor.

Now, with vJASS, they can be declared whenever/wherever you want. To transfer between maps is as simple as copy and paste (assuming there's no name clashing). But what if the names would clash? Easy. Pop it into a scope and make it private, or tweak the name a little.

Globals have come a long ways.

Also, it depends. Globals are okay for transferring a couple pieces of information, but might have trouble with MUI. Structs are for when you need to transfer large amounts of information, like in a knockback system (unit, speed, x/y values, iterations, etc.)