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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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