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

[JASS] Replacing Waits with Timers without JNGP/vJass

Status
Not open for further replies.
Level 4
Joined
Dec 30, 2009
Messages
60
OK before you refer me to JNGP the answer is no.

Reasons:
  1. I don't want people who cant use vJass to become disappointed that my spells wont work on their version of WE.
  2. I don't feel comfortable with a program that is outdated and barely works.
    (Eg. You have to manually update files, some things don't work, if you turn the wrong thing on your maps will crash, etc.) Point me to a STABLE version of JNGP and I MAY consider it.

Anyone that tells me those reasons are just excuses will be ignored.


Now here is what I want to do and why I want to do it:

  • I have a wait inside of a loop. I need the wait to reach as little as .1 seconds.
  • The wait must be at 1 specific place in the loop. It must then continue the loop until conditions are met.
  • The wait is inside an if statement.

I basically need to know what natives to use, and how to use them effectively.

+rep for helpers.
 
JASS:
native CreateTimer          takes nothing returns timer
native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

Basically. The only problem is attaching data to the timer. You could try using a deprecated method. Whatever works, gamecache or whatever those array systems are. However, I don't know how the modders would react toward approving them. =\ Even if it was supposed to be a non-vJass version it might not be approved because it isn't most optimal. D:
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
vJASS isn't required, so using hashtables or gamecaches to store data is perfectly fine, but it will most likely not get recommended unless it's really awesome as efficiency is rather important.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
You can't. You must split it up into several functions. Example:

JASS:
function loop takes nothing returns nothing
    //Do your loop stuff here
endfunction

function Init takes nothing returns nothing
    local timer t = CreateTimer()
    call TimerStart(t, 0.1, true, function loop)
    set t = null
endfunction
To stop it you simply use a global integer and increase it's value until it reaches what you want and then do:
JASS:
    call PauseTimer(t)
    call DestroyTimer(t)
The timer should also be global.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Drenferalis said:
Anyone that tells me those reasons are just excuses will be ignored.

There is no reason to make up an excuse for not using. If you don't like using it fine but its not out-dated, and its perfectly stable. I could crash your World Editor quite easily actually, do you want me to show you how?

Go into the GUI trigger-editor, select "Add Action" and look for your Hashtable functions. Select the one that looks like this:

  • Hashtable - Save Unitpool Hashtable
Now select the field "Unitpool". Your World Editor will crash. Not so stable, now is it?
 
Level 7
Joined
Nov 6, 2009
Messages
279
I don't feel comfortable with a program that is outdated and barely works.
(Eg. You have to manually update files, some things don't work, if you turn the wrong thing on your maps will crash, etc.) Point me to a STABLE version of JNGP and I MAY consider it.

So u are never gonna learn vJASS because u have to CnP the latest JassHelper in the JNGP folder and cause Grimoire doesnt work? Believe me ive been in the same situation and vJASS rock. It changes your life.

Seriously.
 
Level 4
Joined
Dec 30, 2009
Messages
60
You can't. You must split it up into several functions. Example:

JASS:
function loop takes nothing returns nothing
    //Do your loop stuff here
endfunction

function Init takes nothing returns nothing
    local timer t = CreateTimer()
    call TimerStart(t, 0.1, true, function loop)
    set t = null
endfunction
To stop it you simply use a global integer and increase it's value until it reaches what you want and then do:
JASS:
    call PauseTimer(t)
    call DestroyTimer(t)


The timer should also be global.

Such as this?

JASS:
function xWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            
          
        endloop
        set t=null
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
endfunction

This just freezes the spell...
[EDIT:]
And if timer can't be used as a local (for MUI) then why?

And the main reason I don't use JNGP (on a lot of stuff) is that I won't always have access to it like I do the regular editor. If I have to edit something I either have to wait to use my home computer or not be able to test the map or whatever I am working on.

There are also some people who cant use it period. (For whatever reason)

So I like releasing a Jass AND a vJass version of whatever I am working on (except maps of course). This way EVERYONE can use whatever I release.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You need to use the TimerStart function to begin the timer. This native function calls a code parameter which is basically a function. This function is executed every specified duration (if you have it as repeating). You would then need to attach the information from the spell to the timer so that you can reference it in the periodic response function as GetExpiredTimer().

This is what you need for attaching the data:

JASS:
struct s_forData
    unit uData = null
    real r1Data 
    real r2Data

    integer intData
endstruct

globals
    hashtable dataHash = InitHashtable()
endglobals

... // This will "clear" the data from the hashtable, should be used when done with data.
    call RemoveSavedInteger( dataHash, GetHandleId( GetExpiredTimer() ), 1 )
... // This "retrieves" the data from the hashtable.
    call LoadInteger( dataHash, GetHandleId( GetExpiredTimer() ), 1 )
... // This would construct your data struct.
    local s_forData dat = s_forData.create()
    set dat.uData = GetTriggerUnit()
    set dat.intData = GetSpellAbilityLevel( dat.uData, GetSpellAbilityId() )
    set dat.r1Data = GetSpellTargetX()
    set dat.r2Data = GetSpellTargetY()
    // This is for "saving" your data to a handle. (It works like a 2D array, GetHandleId()
    //  works as a unique integer ID for that unit)
    call SaveInteger( dataHash, GetHandleId( yourTimerVar ), 1, dat )
...

This is just an example of how you would use it, and the function names/parameters. Hope this helps.
 
Last edited:
Level 9
Joined
Nov 28, 2008
Messages
704
Nice example, except it uses vJass, which you may notice he doesn't want because he's clearly insane. There is no reason not to use vJass unless you're on Linux. And then the idea is to use vJass anyways in gedit and compile on Windows.
 
Level 9
Joined
Nov 28, 2008
Messages
704
crappy cJass? oO

I take offense to that. cJass introduces defines, and ++/--. Vexorian refused to add += or any of those operators. cJass is the only true path.

Also, who cant use JNGP? I can't on Linux, but then again, I haven't spent the effort (gave up after 10 minutes). And I'm on Windows 99% of the time so meh.
 
Level 9
Joined
Nov 28, 2008
Messages
704
Wrong, but only because learning any programming language helps you learn the rest. Every language has its quirks, but the basic flow of an if/then/else and loop stay the same. Techniques you use here work elsewhere.

When I first learned to program, it was Visual Basic. Half hour and I could do JASS, although it took weeks to learn all of the annoying things you can't do.
 
Status
Not open for further replies.
Top