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

[Solved] Code problem with removing locations

Status
Not open for further replies.
Level 13
Joined
Oct 18, 2013
Messages
691
  • map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set runner=gg_unit_Hmkg_0007
      • Custom script: set lastloc=GetUnitLoc(runner)
      • Custom script: call TimerStart(bs,.03125,true,function doesntwork)
Code:
function doesntwork takes nothing returns nothing
call DisplayTextToPlayer(Player(0),0,0,GetUnitName(runner))
set loco=PolarProjectionBJ(lastloc,10.,0.)
call SetUnitX(runner,GetLocationX(loco))
call SetUnitY(runner,GetLocationY(loco))
call RemoveLocation(lastloc)
set lastloc=loco
call RemoveLocation(loco)

endfunction

Name displayed, unit stuck at map center. so youre forced to create two locations each iteration of a charge trigger, or what? have fun running 18-24 p maps with >10 fps lol.
 

EdgeOfChaos

E

EdgeOfChaos

I don't get what you're doing here at all or what the problem is. Remember that those are references to a location, not the actual location itself. If you set two location references to the same actual location then destroy it, it destroys the actual location, and now both references point to null. That's how it works in almost all high level programming languages
 
Last edited by a moderator:
Level 13
Joined
Oct 18, 2013
Messages
691
i see, i'd have to do
Code:
set lastloc=Location(GetLocationX(loco),GetLocationY(loco))
to accomplish what I was going for.

Is there a real benefit to locations having handles?
 
Level 8
Joined
Mar 19, 2017
Messages
248
I think GetLocationZ to get height of the terrain is the only usefulness of locations. Also most GUI functions, like polarprojectionBJ reference a location, so most GUI user may get stucked on using locations.

The thing you are intending to do don't even need locations to begin with, just use SetUnitX and SetUnitY like this or w/e

sidenote: How to use Code brackets? LOL, well here is a function that does the exact same thing you want (udg_u is a unit variable):

function Move takes nothing returns nothing
local real x = GetUnitX(udg_u)
local real y = GetUnitY(udg_u)
local real angle = GetUnitFacing(udg_u)*bj_DEGTORAD
local real dx = GetUnitX(udg_u) + 10.*Cos(angle)
local real dy = GetUnitY(udg_u) + 10.*Sin(angle)

call DisplayTextToPlayer(Player(0),0,0,"this works")
call SetUnitX(udg_u, dx)
call SetUnitY(udg_u, dy)


endfunction
 
Is there a real benefit to locations having handles?
Yes, there are some.
Beeing an object makes all variables only beeing "Pointers" instead of beeing a value as reals are. Now cause they are "pointers", each access over such a pointer will affect the same object allowing to reuse 1 DataObject over multiple functions with only 1 variable instead of having 2 variables for each code part and also does not enforce you any specific variable usage.
It basicly allows to split up the code into multiple indepented parts without having always to recalc x/y/z, or having to refer to an array Index which requiers you to make sure that it is valid for the whole time.
Another benefit is, it allows to avoid controling longer timers by faster timer.

edit: Pretty sure that if one uses vjass this benefit becomes smaller but in default jass2 it is a big plus.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
Is there a real benefit to locations having handles?
Yes there is a benefit because JASS primitive types are 32bit so could not fit a complex type like a location (at least 2 32 bit float values). Hence it has to be a separate object with a 32bit handle reference to it.

Java has a similar limitation, with all Object values being either 32bit (default) or 64bit (long handle mode) object handles. C++ and C does not have such a limitation, since it does support nesting complex types, leaving the choice to do so up to the programmer.
 
Status
Not open for further replies.
Top