Functions as Variables

Moradiae

TH.net Regular
Reaction score
14
HNY everyone :)

SOLVED see 3rd post


Ignoring anomalies within the trigger, this is what I am trying to do:
Trigger:
  • Actions
    • Floating Text - Create floating text..
    • For each loop integer A from 0 to 100, Do Actions
      • Actions
        • Floating Text - Set the velocity of (Last created floating text) to [speed] towards f(A) degrees
        • Wait 0.05 seconds before next loop


So the (Last created floating text) will move at a constant speed along the angle defined by the function f of A, a dynamic floating text of sort, if you like.

The above trigger is clearly not going to work, it is simply to illustrate what I am trying to do. So my question is how should I go about trying to achieve this?



Essentially, in the end, it should be possible to have a floating texts such that they:

Last x seconds
Have font size f(x) with velocity g(x) towards h(x) degrees
and is mui​


Any helps and pointers will be most welcomed :)
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Basically what you should do is create the functions first:
JASS:
function x takes integer number returns integer
    return (number * 2)
endfunction

function g takes integer number returns integer
    return (number - 2)
endfunction

function h takes integer number returns integer
    return (number + 2)
endfunction


Then your trigger would set three integer/real variables to f(integer), g(integer) and h(integer), which you could then use in the floating text trigger.

Trigger:
  • Floating Text
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_FontSize = f(YourInteger)
      • Custom script: set udg_Velocity = g(YourInteger)
      • Custom script: set udg_Angle = h(YourInteger)
      • ---Floating Text Actions---
 

Moradiae

TH.net Regular
Reaction score
14
oh setting the functions isn't really the problem here, but it's something more like finding a way to vary the variable over time, you know what I mean?

Normally with floating texts, we just set the size to be a constant, a, for example.
i.e.
Trigger:
  • Actions
    • Floating Text - Create Floating text that reads [my text] with size [a] at [my position]


but what I am looking for is a way to make it so that [a] changes over time

I hope this clears up my question :eek:


thanks for the jass input btw, I would've done it in gui in some way but this is a good opportunity to slowly incorporate jass into my triggers :p





---edit---

I think it would be something like

Trigger:
  • Floating Text
    • Actions
      • Floating Text - Create Floating text that reads (my text)
      • Set myFloatingText = (last created floating text)
      • Set x = 0.00


Trigger:
  • Varying x
    • Events
      • Time - Every 0.04 seconds of game-time
    • Conditions
    • Actions
      • Set x = x+1
      • Floating Text - Set the velocity of (myFloatingText) to 800 towards f(x) degrees


So we get floating text going at whatever direction f(x) gives




---edit 2---
ok, I've finally got an answer to my own question now (the above solution is not mui), so here goes:

First, hashtable would be ideal, so I read this introductory tutorials and another tutorial more focused on going mui with hash

So the basic structure will be like so:
Add unit (floating text, in this case) to group
Effect is applied periodically to every unit in group (effect = change speed, angle, etc. of the floating text)
Each unit's remaining time in the group is stored in a hashtable using their handle ID
The unit is removed from group whenever the remaining time runs out​


But the problem is that there's no such thing as a floating text group.
But we can use array here like so:

after a few testings, i found out that the handle ID of a floating text is a number starting from 99 and counts down to 0.
This is pretty cool since it automatically eliminate the needs for indexing like this or this which are both somewhat complicated.

so each floating text can be stored individually in an array using the built-in recycling handleIDs

Trigger:
  • Adding FT to hash
    • Actions
      • Set Temp_string = (my text)
      • Floating Text - Create Floating text that reads Temp_string ...
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan to 2.00 sec.
      • Set Temp_FT = (Last created floating text)
      • Custom Script: set udg_FThandle = GetHandleID(udg_Temp_FT)
      • -------storing floating text and its string with its own handle as index-------
      • Set FTunit[FThandle] = (last created floating text)
      • Set FTstring[FThandle] = Temp_string
      • Hashtable - Save 0 as 0 of FThandle in hash


so we wanna pick all floating text in "group", but we have no such thing
but we also know that the handle id range from 99 to 0, so we can simply do the loop:

Trigger:
  • Animating FT in hash
    • Events
      • Time - Every 0.04 sec. of game time
    • Conditions
    • Actions
      • For each loop (integer A) from 0 to 99, do (Actions)
        • Loop - Actions
          • Set x = (Real((Load 0 of (Integer A) from hash)))
          • If (All conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer(x)) Less than 50
            • Then - Actions
              • -------Speed and direction-------
              • Floating Text - Set the velocity of FTunit[(Integer A)] to f(x) towards g(x) degrees
              • -------Size (updating size means we also have to update the string, that's why we also save the string-------
              • Floating Text - Change text of FTunit[(Integer A)] to FTstring[(Integer A)] using font size h(x)
              • Hashtable - Save ((Integer(x)) + 1) as 0 of (Integer A) in hash
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Integer A) in hash
              • -------FT handles recycle automatically, so no more cleaning needed-------


done :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top