• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Player not recognized?

Status
Not open for further replies.
Level 5
Joined
Aug 8, 2008
Messages
113
I thought I give JASS a whirl, so I read some tutorials on different sites and looked at some prexisting jass scripts with errors and how they were fixed. So after this I thought I give it a whirl in trying to figure it out for myself.

Here is a script I tried to modify the gui

JASS:
 //the function below is suppose to create a footman for red
function T_Creuni takes nothing returns nothing
    Local player Red = player(0) //Line that messes up
    call CreateNUnitsAtLoc( 1, 'hfoo', Red , GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
    Set Red = null
endfunction

//===========================================================================
function InitTrig_Test_1 takes nothing returns nothing
    local trigger t = CreateTrigger(InitTrig_Test_1)
    call TriggerAddAction( t, function T_Creuni )
    set t = null
endfunction
 
Last edited:
Local player "Local" --> "local"

Set Red = null"Set" --> "set"

jass is case sensitive so it makes a difference if you write lower- or uppercase. Also in jass you have the possibility to use all natives. Use the normal CreateUnit function to create a unit, because it is more efficient.

This CreateNUnitsAtLoc function, if you look at it's structure... it again calls other functions... so it's not the fastest way.

I guess you use JNGP? You can look up all the functions in a list there, so you can see how each of the function is implemented.

Edit: CreateTrigger() doesn't take any argument. So just open and close brackets without anymore input.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
As Iceman said, the keywords should be as:
set
call
local
Red = player(0) into Red = Player(0)

This is, because as he said, it is case-sensitive, and player is data type, and Player is native function


The correct version should be:

JASS:
 //the function below is suppose to create a footman for red
function T_Creuni takes nothing returns nothing
    local player Red = Player(0)
    call CreateNUnitsAtLoc( 1, 'hfoo', Red , GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
    set Red = null
endfunction

//===========================================================================
function InitTrig_Test_1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function T_Creuni )
    set t = null
endfunction

more optimized way:

JASS:
 //the function below is suppose to create a footman for red
function T_Creuni takes nothing returns nothing
    Local player Red = player(0) //Line that messes up
    call CreateUnit(Red, 'hfoo', 0, 0, 0)
    //you dont need to null player types
endfunction

//===========================================================================
function InitTrig_Test_1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function T_Creuni )
    set t = null
endfunction
 
Level 5
Joined
Aug 8, 2008
Messages
113
Edit: CreateTrigger() doesn't take any argument. So just open and close brackets without anymore input.


JASS:
//* is the only way it works...it wont let me set a variable for the trigger
//*  if I do it sends me to the title screen
function InitTrig_Test_2 takes nothing returns nothing
    set gg_trg_Test_2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Test_2, function UCTR )
endfunction



Also in jass you have the possibility to use all natives. Use the normal CreateUnit function to create a unit, because it is more efficient.
.
I can't seem to find it. I only see CreateNUnit


-------Other concerns--------
.

I was wondering how do I set a variable or array for the footman unit? when I try local unit foot = 'hf00' it doesn't work
 
Because function UCTR doesnt exist, it throws you an error maybe.

I can't seem to find it. I only see CreateNUnit
Look in edo's post. He used the CreateUnit function. ;)

local unit foot = 'hf00' it doesn't work
'hf00' is the rawcode of the unit. It's just an integer type. unit is a complex type.

You can initialisize your local variable like this:

local unit footman = CreateUnit(Player(0), 'hfoo', 0, 0, 0)

or like this
JASS:
local unit footman
... // some code
set footman = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
... // some code
set footman = null
Don't forget to null local handles.
 
Level 5
Joined
Aug 8, 2008
Messages
113
JASS:
//what I meant to say is that this trigger works

function uc takes nothing returns nothing
  local player r = Player(0)
  local unit f = CreateUnit( r, 'hfoo', 1, 655, 288)
  // Creates a unit for the red player.



 // how can i turn hf00  into a variable without having to refer to it each time




  //  call CreateUnit(r, 'hfoo', 0, 0, 0) the original create unit.
  // call f..... not needed creates the unit when you declare it
   // Don't  need to null player types
  set f = null 
endfunction

//===========================================================================
function InitTrig_Test_2 takes nothing returns nothing
    set gg_trg_Test_2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Test_2, function uc )
endfunction



JASS:
// and this one doesn't work. It sends me to the title screen

function uc takes nothing returns nothing
  local player r = Player(0)
  local unit f = CreateUnit( r, 'hfoo', 1, 655, 288)
  // Creates a unit for the red player.

  //  call CreateUnit(r, 'hfoo', 0, 0, 0) the original create unit.
  // call f..... not needed creates the unit when you declare it
   // Don't  need to null player types
  set f = null 
endfunction

//===========================================================================
function InitTrig_Test_2 takes nothing returns nothing
    local trigger t = CreateTrigger( )
    call TriggerAddAction( t, function uc )
    set t = null
endfunction

The only difference between the two is that I set the trigger as a local in the second one. I don't understand why it doesn't work
 
'hfoo' can bet stored in an integer variable.

Do you use JNGP or normal World Editor?

JNGP
WorldEditor
JASS:
globals
    integer footmanId = 'hfoo'
endglobals
Create integer variable footmanId in variable editor. And then somewhere in init do..
set udg_footmanId = 'hfoo'

And it brings you an error probably because you use wrong function name for init function in one of your codes. (you just copied all)

edit: yo, waterknight said it already
 
Level 5
Joined
Aug 8, 2008
Messages
113
If it sends you to the title screen, there is a syntax error. It does not cause a problem for me, maybe you activated both triggers (under the same name)?

'hfoo' is an integer expression. So you can store it in an integer variable.
After saving it, the map starts.

But it doesn't create a unit

=(


Im missing something in the ini trigger.

In JNGP, if you are using vJass, you should save everytime, sometimes even twice if you started wrongly before you hit Test Map in order to ensure JassHelper runs.
Will do from now on.


Then you can create you one globals block. Just do it on top outside all functions. Here you can create all global variabls you want. And variables created in a globals block can be used by any other function.
Global Block gave the same problem, it doesn't create the unit.
 
Level 5
Joined
Aug 8, 2008
Messages
113
Because you don't have an event. The function never gets fired.

Or you directly call your function in initcall uc()

... or you add an event with call TriggerRegister...

o


JASS:
function lgh takes nothing returns nothing
   if (  (light == 1 ) ) then
        return false
    endif
    if ( ( GetTimeOfDay() >= 6.00 ) ) then
        return false
    endif
    if (  ( GetTimeOfDay() <= 18.00 ) ) then
        return false
    endif
    return true
endfunction

I've tried to make this optimized but cant figure out how to do it.... also when declaring global variables how do you access the private outside of the global?
 
If you make a globals block inside a library or a scope, sometimes it makes sense to declare functions or variables as private.

You only can access these privates inside your library or scope.

And... what is this function? That's totaly new and has nothing todo with unit creation anymore.

What do you want to achieve?

And also, think of "or" and "and" ... they can simplify your function a lot by combining your ifs.

Also, you can directly return en expression which returns a boolean. Example:
return (1==2) (returns false)
return ((1==1) (returns true)

What I see is that you write returns nothing but in function you try to return a boolean. That doesnt make sense. Change it to returns boolean (else it throws an error)
 
Level 5
Joined
Aug 8, 2008
Messages
113
I Created two units so now im trying to have a lightning effect attach/connect between the two of them.

this is what I have so far

JASS:
scope Test initializer Init
globals
     private integer light = 1
     private trigger t = CreateTrigger(  )

endglobals


// lgh takes nothing returns boolean
//  if  light == 1 And GetTimeOfDay() >= 6.00 And GetTimeOfDay() <= 18.00 then
//       return false
//       else
//       return true
//   endif
//
//endfunction
//function lgh2 takes nothing returns boolean
//   if  light == 2 And GetTimeOfDay() >= 6.00 And GetTimeOfDay() <= 18.00 then
//       return false
//       else
//       return true
//   endif
//
//endfunction
//function lgh3 takes nothing returns boolean
//   if  light == 2 And GetTimeOfDay() <= 6.00 And GetTimeOfDay() >= 18.00 then
//       return false
//        else
//       return true
//   endif
//
//endfunction


function uc takes nothing returns nothing
  local player r = Player(0)
  local integer foot = 'hfoo'
  local integer rife = 'hrif'
  local unit re = CreateUnit( r, rife, 1, 655, 288)
  local unit f = CreateUnit( r, foot, -1, -655, -288)
  local lightning li
  // call AddLightningLoc( "SPLK", GetUnitLoc(re), GetUnitLoc(f) )
  // Creates a unit for the red player.
  // hfoo is the reference footman
  //  call CreateUnit(r, 'hfoo', 0, 0, 0).....the original create unit. 0,0,0 are coordinates.
  // call f..... not needed creates the unit when you declare it
   // Don't  need to null player types
  set f = null 
  
       if  light == 1 and GetTimeOfDay() >= 6.00 and GetTimeOfDay() <= 18.00  then
       //  call CreateNUnitsAtLocFacingLocBJ( 1, 'hrif', Player(0), GetRectCenter(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
    call AddLightningLoc( "SPLK", GetUnitLoc(re), GetUnitLoc(f) )
    Set li = GetLastCreatedLightningBJ()
    // call DestroyLightningBJ( GetLastCreatedLightningBJ() )
    call SetLightningColorBJ( GetLastCreatedLightningBJ(), 0.00, 255.00, 0.00, 1 )
    set light = 2
    else
        call DoNothing(  )
    endif
    
     if  light == 2 and GetTimeOfDay() >= 6.00 and GetTimeOfDay() <= 18.00  then
       //  call CreateNUnitsAtLocFacingLocBJ( 1, 'hrif', Player(0), GetRectCenter(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
    // call AddLightningLoc( "SPLK", GetUnitLoc(GetTriggerUnit()), GetRectCenter(GetPlayableMapRect()) )
    // call DestroyLightningBJ( GetLastCreatedLightningBJ() )
    // call SetLightningColorBJ( GetLastCreatedLightningBJ(), 0.00, 255.00, 0.00, 1 )
       call MoveLightningLoc( li , GetUnitLoc(re), GetUnitLoc(f) )
    // set light = 2
    else
        call DoNothing(  )
    endif
     if  light == 2 and GetTimeOfDay() <= 6.00 and GetTimeOfDay() >= 18.00  then
       //  call CreateNUnitsAtLocFacingLocBJ( 1, 'hrif', Player(0), GetRectCenter(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
    // call AddLightningLoc( "SPLK", GetUnitLoc(GetTriggerUnit()), GetRectCenter(GetPlayableMapRect()) )
     call DestroyLightningBJ( li )
     set li = null
    // call SetLightningColorBJ( GetLastCreatedLightningBJ(), 0.00, 255.00, 0.00, 1 )
    // call MoveLightningLoc( li , GetUnitLoc(re), GetUnitLoc(f) )
    // set light = 2
    else
        call DoNothing(  )
    endif
endfunction

//===========================================================================
function Init takes nothing returns nothing
    set gg_trg_Test_2 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Test_2 , function uc )
    call TriggerAddAction( gg_trg_Test_2 , function lgh )
endfunction
endscope
 
Last edited:

Wrda

Spell Reviewer
Level 28
Joined
Nov 18, 2012
Messages
1,993
JASS:
globals
     private integer light = 1
/********************************************************/
//                    ! ! !
     private trigger t = CreateTrigger(  ) //WTF IS THIS FOR? You don't even use it
//                    ! ! !
/********************************************************/
endglobals
You shouldn't use the DoNothing() function, it's just trash, and you have to clean it, because it does nothing.
Automatically move the if light == 2 and GetTimeOfDay() >= 6.00 and GetTimeOfDay() <= 18.00 then to the first ELSE condition block, and the if light == 2 and GetTimeOfDay() <= 6.00 and GetTimeOfDay() >= 18.00 then to the second ELSE condition block.
 
Status
Not open for further replies.
Top