• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Problem with my function

Status
Not open for further replies.
Level 4
Joined
Feb 28, 2014
Messages
70
I created this function to revive a hero on player's start location after certain time, the function is working fine, the only problem is that it doesn't show the time, only the timer window with the message but not the time that left to revive.

This is the code

JASS:
function HeroRevive takes unit u, integer i, real r, location p returns nothing
local string s = "Respawn in:"
local timer array t
local timerdialog array td
set u = GetDyingUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set r = ( 2.00 * I2R(GetHeroLevel(u)) )
set p = GetPlayerStartLocationLoc(Player(i))
call StartTimerBJ( t[i], false, r)
call CreateTimerDialogBJ( t[i], s )
set td[i] = GetLastCreatedTimerDialogBJ()
call TimerDialogDisplayForPlayerBJ( false, td[i], Player(i) )
call TriggerSleepAction(r)
call ReviveHeroLoc( u, p, true )
call PanCameraToTimedLocForPlayer( Player(i), p, 0 )
call SelectUnitForPlayerSingle( u, Player(i) )
call DestroyTimerDialog( td[i] )
call RemoveLocation(p)
set u = null
set t[i] = null
set td[i] = null
endfunction
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
If you are coding in Jass you should inline your function calls. All those BJs are horrible for speed and efficiency.

The timer does not start because you never create the timer.

You need to do this.

JASS:
local timer t = CreateTimer()

Also remove the timerdialog array and use a local timerdialog to show the timer to the player.
You also destroy the timer dialog which means that it will never show to the player.

Here is how this function should be written.

JASS:
function HeroRevive takes unit u, real r, location loc, boolean b returns nothing
        local string s = "Respawn in:"
        local timer t = CreateTimer()
        local timerdialog td = CreateTimerDialog(t)
        local integer p = GetPlayerId(GetOwningPlayer(u))
        local real x = GetLocationX(loc)
        local real y = GetLocationY(loc)
        call TimerStart( t, r, false, null)
        if (GetLocalPlayer() == Player(p)) then
            call TimerDialogDisplay( td, true)
        endif
        call TriggerSleepAction(r)
        call ReviveHero( u, x, y, true )
        if (GetLocalPlayer() == Player(p)) then
            call PanCameraToTimed(x, y, 0)
            call ClearSelection()
            call SelectUnit(u, true)
        endif
        call DestroyTimerDialog( td )
        if (b) then
            call RemoveLocation(loc)
        endif
        set u = null
        set t = null
        set td = null
    endfunction

Call it from GUI using this custom script.
  • Set tempUnit = (Triggering unit)
  • Set tempReal = (time till reviving)
  • Set tempPoint = (location to revive the unit at.)
  • Custom script: call HeroRevive( udg_tempUnit, udg_tempReal, udg_tempPoint, true)
Note: the above function is MUI but it uses waits so the time will vary.
 
Last edited:
Level 4
Joined
Feb 28, 2014
Messages
70
  • Dead
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is A Hero) Equal to True
    • Actions
      • Set TempUnit = (Dying unit)
      • Set TeamReal = (2.00 x (Real((Hero level of TempUnit))))
      • Set TempPoint = ((Owner of TempUnit) start location)
      • Custom script: call HeroRevive( udg_TempUnit, udg_TempReal, udg_TempPoint, true)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
  • Dead
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) is A Hero) Equal to True
    • Actions
      • Set TempUnit = (Dying unit)
      • Set TeamReal = (2.00 x (Real((Hero level of TempUnit))))
      • Set TempPoint = ((Owner of TempUnit) start location)
      • Custom script: call HeroRevive( udg_TempUnit, udg_TempReal, udg_TempPoint, true)

It should work fine then. What time is getting displayed on the timer dialog window in game ?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
I guess because TriggerSleepAction only works in TriggerActions, and not in generic functions. Using a timer would be better anyway.
But you of course can stay in GUI. Before you just start using JASS, you anyway should read some tutorials first.

I thought it was something stupid. I couldn't remember though. Thanks Iceman.
 
Level 4
Joined
Feb 28, 2014
Messages
70
I guess because TriggerSleepAction only works in TriggerActions, and not in generic functions. Using a timer would be better anyway.
But you of course can stay in GUI. Before you just start using JASS, you anyway should read some tutorials first.

Well, my first function was working fine with the TriggerSleepAction, the problem was only that it didn't show the time, only the window with the string...
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
JASS:
local timer array t
local timerdialog array td
set u = GetDyingUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set r = ( 2.00 * I2R(GetHeroLevel(u)) )
set p = GetPlayerStartLocationLoc(Player(i))
call StartTimerBJ( t[i], false, r)

this is just wrong. You dont need to make them arrays, since they are locals, so they are always unique to the running scope and dont share state between JVM instances.

Basically what you dont do is actually create the timer, you just try to start it, but there is no created timer to begin with
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
local integer p = GetPlayerId(GetOwningPlayer(u)) + 1 the +1 is actually not needed and will cause different players to show the effect(Local block), because all your functions are natives, and they expect 0 based indexing for players

Also wait kind of sucks, but for the sake of making it easy to understand, I think its fine
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
local integer p = GetPlayerId(GetOwningPlayer(u)) + 1 the +1 is actually not needed and will cause different players to show the effect(Local block), because all your functions are natives, and they expect 0 based indexing for players

Also wait kind of sucks, but for the sake of making it easy to understand, I think its fine

Ya I know wait sucks and I knew I was missing something stupid. He was using it to call from GUI and for some reason I added the + 1 in there lol thanks.
 
Status
Not open for further replies.
Top