• 🏆 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!

Spawning Unit(s)

Status
Not open for further replies.
Level 13
Joined
Aug 4, 2012
Messages
1,022
Well this vJASS doesn't work :/ :/
Can someone fix it??
I want to spawn a unit
But this vJASS won't work
JASS:
function SpellTester takes integer u returns unit          // You could return the unit so you can use or referring later...
  set integer u = 'U000'                                   // Apply the unit raw code, don't forget the unitype goes in single quotes
  return CreateUnit(Player(0), u, -1550, -2360, 180)       // Now it has the right arguments...
endfunction
 
Last edited by a moderator:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
JASS:
function SomeFunction takes nothing returns nothing
    call CreateUnit(Player(0), 'hpea', 1, 1, 180)
endfunction

this worked for me atleast.

also dont use a argument like that.

JASS:
function SpellTester takes integer u returns unit          // You could return the unit so you can use or referring later...
  set integer u = 'U000'                                   // Apply the unit raw code, don't forget the unitype goes in single quotes
  return CreateUnit(Player(0), u, -1550, -2360, 180)       // Now it has the right arguments...
endfunction


>>>>>>


function SpellTester takes nothing returns nothing         // You could return the unit so you can use or referring later...
  local integer i = 'U000'                                   // Apply the unit raw code, don't forget the unitype goes in single quotes
  call CreateUnit(Player(0), i, -1550, -2360, 180)       // Now it has the right arguments...
endfunction
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
What do you want the code to do?
- Create units at a defined position by only passing the unittype as an argument?
- Or just create units of defined type at a defined position without passing any arguments?

€ Oh yea and pleaaaaaaaase next time chose a title for your thread which gives an idea what its about.
 
Level 13
Joined
Aug 4, 2012
Messages
1,022
But I want just using " call " command, not " return " command
EDIT:
Something like this right?? Won't work Y..Y
JASS:
function SpellTester takes integer u, -1550, -3220, 180 returns unit
    local unit u
    set u =  = SpellTester('U000', -1550, -3220, 180)
    return CreateUnit(Player(0), u, -1550, -3220, 180)
endfunction
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Do you mean just create a unit at some point in the map?

Creating the function itself won't do that, you need to put it in an init function or a trigger action which then does the call for you.

JASS:
library lib initializer init

private function init takes nothing returns nothing
  local location yourLoc = Loc(coordinateX, coordinateY)
  call CreateUnitAtLoc(Player(0), 'hfoo', yourLoc, 0)
endfunction

endlibrary

This will create a footman for Player 1 at the coordinates given immediately at the start of the map.

Functions can create objects without returning them, just put "takes nothing." The function will still do whatever you asked it. You only return values if you are calculating something another part of your system will need down the road...

Like for example you want to keep track of that unit in particular. Then perhaps you might return it. But I never really return native objects, as they are usually put in auxiliary data structures.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
But I want just using " call " command, not " return " command
EDIT:
Something like this right?? Won't work Y..Y
JASS:
function SpellTester takes integer u, -1550, -3220, 180 returns unit
    local unit u
    set u =  = SpellTester('U000', -1550, -3220, 180)
    return CreateUnit(Player(0), u, -1550, -3220, 180)
endfunction

Change the above to this.
JASS:
function SpellTester takes integer i returns nothing
    call CreateUnit(Player(0), i, -1550, -3220, 180)
endfunction

If you are trying to pass in the other values do this.
JASS:
function SpellTester takes integer i, integer i1, integer i2, integer i3 returns nothing
    call CreateUnit(Player(0), i, i1, i2, i3)
endfunction

You should really look into a jass tutorial as you have made a lot of small mistakes that should almost never be made.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
JASS:
private function init takes nothing returns nothing
  local location yourLoc = Loc(coordinateX, coordinateY)
  call CreateUnitAtLoc(Player(0), 'hfoo', yourLoc, 0)
endfunction

why dont simply use the original function lol?
JASS:
call CreateUnitAtLoc(Player(0), 'hfoo', yourLoc, 0)

Because if you put it in init then it will actually spawn a unit at the start of the map. I am guessing that's all he wants. Outside of init he'd need to call it through an event.
 
Status
Not open for further replies.
Top