• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] How to use vJass without vJass Class Core System?

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
How to use Jass without Jass Class Core System?

Here is an example of a JASS Class code:
JASS:
//! runtextmacro Variables()
unit u
integer i
real r
string s
//! runtextmacro Actions()
set u = CreateUnit(Player(0), 'hfoo', 0.00, 0.00, 270)
set i = 5+67+8*10
set r = GetRandomReal(1.00, 50.00)
set s = UnitId2String('u')
call PrintInteger(i)
call PrintReal(r)
call Print(s)
//! runtextmacro End_Code()

BUT in order for it to work we need this Core System:
JASS:
native GetPlayerUnitTypeCount takes player p, integer unitid returns integer
native GetUnitGoldCost takes integer unitid returns integer
native GetUnitWoodCost takes integer unitid returns integer
native GetUnitBuildTime takes integer unitid returns integer

native CreepsOnMap takes nothing returns boolean
native UnitAlive takes unit id returns boolean

library Core
    function Print takes string msg returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,msg)
    endfunction
    function PrintInteger takes integer i returns nothing
        call Print(I2S(i))
    endfunction
    function PrintReal takes real r returns nothing
        call Print(R2SW(r, 0, 9))
    endfunction
endlibrary

//! textmacro Variables
    globals
//! endtextmacro
//! textmacro Actions
    endglobals
    function Run takes nothing returns nothing
//! endtextmacro
//! textmacro End_Code
    endfunction
    struct Init extends array
        private static method init takes nothing returns nothing
            call DestroyTimer(GetExpiredTimer())
            call Run.execute()
        endmethod
        private static method onInit takes nothing returns nothing
            call TimerStart(CreateTimer(),0,false,function thistype.init)
        endmethod
    endstruct
//! endtextmacro

//! textmacro Function
    function Run takes nothing returns nothing
//! endtextmacro


//! textmacro Lesson2
    local attacktype test
    
    set hello = null
    set test = hello
//! endtextmacro

//! textmacro Lesson6
    function TheFunction takes nothing returns nothing
    endfunction
    function DisplayMessage takes nothing returns nothing
        call Print("You have called Display Message")
    endfunction
//! endtextmacro

//! textmacro Project1
    struct Project1 extends array
        private static method check takes nothing returns nothing
            local integer unitCount = 0
            local integer surviveCount = 0
            local group g = CreateGroup()
            local unit u
            
            call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                call GroupRemoveUnit(g, u)
                
                if (UnitAlive(u)) then
                    set unitCount = unitCount + 1
                    if (GetOwningPlayer(u) == Player(0)) then
                        set surviveCount = surviveCount + 1
                    endif
                endif
            endloop
            
            if (surviveCount == unitCount) then
                call PauseTimer(GetExpiredTimer())
                call DestroyTimer(GetExpiredTimer())
                call Print("Congragulations "+GetPlayerName(Player(0))+", you won!")
            endif
            
            call DestroyGroup(g)
            set g = null
        endmethod
        
        private static method onInit takes nothing returns nothing
            set player0 = Player(0)
            set player1 = Player(1)
            set player2 = Player(2)
            set player3 = Player(3)
            set player4 = Player(4)
            set player5 = Player(5)
            set player6 = Player(6)
            set player7 = Player(7)
            set player8 = Player(8)
            set player9 = Player(9)
            set player10 = Player(10)
            set player11 = Player(11)
            
            call TimerStart(CreateTimer(),.03125,true,function thistype.check)
        endmethod
    endstruct
//! endtextmacro

//! textmacro Lesson14
    struct Lesson14 extends array
        private static method onInit takes nothing returns nothing
            set i[4] = 2422
            set i[23] = 14291
            set i[931] = 14
            set i[0] = 99
            set i[93] = -4214
            
            set i[999] = 999
        endmethod
    endstruct
//! endtextmacro

//! textmacro Lesson14P2
    struct Lesson14P2 extends array
        private static method init takes nothing returns nothing
            local group g
            local unit u
        
            call SetUnitScale(riflez[1423], 5, 5, 5)
            
            if (riflez[1423] == null) then
                set g = CreateGroup()
                
                loop
                    set u = FirstOfGroup(g)
                    exitwhen u == null
                    call GroupRemoveUnit(g, u)
                    
                    call Print(GetUnitName(u) + " is set to the wrong position")
                endloop
                
                call DestroyGroup(g)
                set g = null
                
                return
            else
                call Print(GetUnitName(riflez[1423])+" is set to the correct position")
            endif
            
            if (GetOwningPlayer(riflez[1423]) != Player(2)) then
                call Print("Unit owner is incorrect")
                
                return
            endif
            
            call SetPlayerAlliance(Player(2), Player(0), ALLIANCE_SHARED_VISION_FORCED, true)
        endmethod
        private static method onInit takes nothing returns nothing
            call TimerStart(CreateTimer(),.1,false,function thistype.init)
        endmethod
    endstruct
//! endtextmacro
How can i make a code that does the same thing exactly as the first one BUT without using that core system?
How can i choose WHEN i want the trigger to run?

GUI examples:
  • Map initialization
  • Unit - A unit Dies
  • Player - Player 1 (Red) leaves the game
  • Unit - A unit Begins channeling an ability
  • Time - Elapsed game time is 5.00 seconds
  • Player - Player 1 (Red) Presses the Left Arrow key
  • Unit - Peasant 0001 <gen>'s life becomes Less than 100.00
  • Player - Player 1 (Red) types a chat message containing test as An exact match
HOW?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I know what you mean, I did ask that too I don't work with the core it sucks in my opionion. anyway you can allways add the event you want and then convert into jass and if you want to change the event you can find it in the function list if I remember right but if you don't find it there you can just create a new trigger and make a new event then copy it over
JASS:
function InitTrig_TRIGGER_NAME takes nothing returns nothing
    set gg_trg_TRIGGER_NAME = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TRIGGERNAME, EVENT HERE)
    call TriggerAddAction( gg_trg_TRIGGERNAME, function FUNCTION_NAME_OF_CHOISE )
endfunction

http://www.hiveworkshop.com/forums/world-editor-help-zone-98/jass-question-206939/
 
Level 20
Joined
Jul 12, 2010
Messages
1,717
JASS:
function InitTrig_TRIGGER_NAME takes nothing returns nothing
    set gg_trg_TRIGGER_NAME = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TRIGGERNAME, EVENT HERE)
    call TriggerAddAction( gg_trg_TRIGGERNAME, function FUNCTION_NAME_OF_CHOISE )
endfunction
this helps a bit BUT doesn't BJs leak or smth?>_<
also where do i put that? in the beginning of the trigger before setting the variables or at the end/middle? jass is so confusing on choosing when you want a trigger to run:(
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
instead of calling PrintInteger and PrintReal you can call call BJDebugMsg(string)
and for string to get real use R2S(real) and for integer use I2S(integer), for multiple prints use + operator, example:
JASS:
local integer i = 4
local real r = 5
call BJDebugMsg("real r is: " + R2S(r) + " and integer i is: " + I2S(i))
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
because your learning vJass and dont need to know how to do those things right now :p
 
Level 20
Joined
Jul 12, 2010
Messages
1,717
instead of calling PrintInteger and PrintReal you can call call BJDebugMsg(string)
and for string to get real use R2S(real) and for integer use I2S(integer), for multiple prints use + operator, example:
JASS:
local integer i = 4
local real r = 5
call BJDebugMsg("real r is: " + R2S(r) + " and integer i is: " + I2S(i))
yeah the "call Print" function was provided from the textmacros the JASS Class provided.
And I was wondering why i always got syntax errors for textmacros when i tried to code without the JASS Class Core System lol..

look, if you create a normal trigger add a event in GUI and then convert it you will find where it is
I tried that but it's a bit confusing >_<

because your learning vJass and dont need to know how to do those things right now :p
Well actually after getting help from a guy i came up with this:
JASS:
globals
    integer i
endglobals

function IntegerTest takes nothing returns nothing
    set i = 3
    call BJDebugMsg(I2S(i))
endfunction

function InitTrig_Map_Init takes nothing returns nothing
    local timer tim = CreateTimer()
    call TimerStart(tim, 0.50, true, function IntegerTest)
endfunction
which is more "correct" and easier than the way they use in JASS Class IMO
 
Well, different approaches suit different people. Most learned just through converting text, but I think the method the JASS class uses might help you understand the concepts a bit more—or at least it may help you focus on what needs to be understood rather than being confused with the syntax of everything.

However, if you do want to do something in JASS, you can either convert GUI to JASS and try to optimize the code (inline BJs, change names, etc.) or you can use the function list for TESH and find out which natives to use to do what you want to do. For example, if you want to kill a unit, search "Kill" in the function list. You'll find the native KillUnit. Of course, not all are that easy to find. If you can't find the native you want, just make it in GUI, convert to custom text, then look up the BJ and see how it is done. :)
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
The functions and stuff will be covered in JASS Class soon.

It's too much to make beginners work in lots of syntax that they don't recognize. It's much easier for them if it's categorized like GUI.

This would be the code if the macros weren't being used..

JASS:
struct Code extends array
    private static method onInit takes nothing returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "Hello World")
    endmethod
endstruct

Tell me, would you rather be working in all of that nonsense that you 100% don't understand, or work in categories with GUI and have that stuff slowly introduced?

Remember how the variables macro was being used? Later, the globals block was introduced and variables macro was taken out. The same thing will eventually happen to the function block : ).

The tools in the JASS Class Map are only meant to help you learn and aren't meant to be used outside of the class. By week 6 or so, you won't be using any JASS Class tools and will be writing code from scratch =P.

edit
btw, the primary reason that most people can't learn programming is because of the wall of functions.. you can't do anything without functions

the approach taken in the JASS Class eliminates this wall so that anyone can learn

there is a reason that so many people fail traditional tutorials

the very few that can get past them usually struggle with all of their might to do so

so far, in these maps, I haven't seen anyone struggle to do the stuff in them : p, which is a very good sign =). They're all learning JASS effortlessly, although they can't code anything for their own maps yet : p.

So just be patient ^_^.
 
Status
Not open for further replies.
Top