[JASS] Global variable doesn't work

Deleted member 231919

D

Deleted member 231919

I am new to jass, just trying to figure out how to initialize and use a global variable. The code below doesn't work for some reason. I have been asking chat gpt for help and it has been very helpful in accelerating my learning with jass. I am using TESH WC3 editor. I can get this code to work with local variables, but needing to use globals. I have tried declaring GUI globals and then using udg_currentStrength and udg_newStrength, but that doesn't work either. I know multiple programming languages, so I am not new to coding. Thanks for any help.

JASS:
globals
    real currentStrength = 0.0
    real newStrength = 0.0
endglobals


function Trig_Dart_Transform_Actions takes nothing returns nothing
  
    // Get the hero's current strength
        set currentStrength = GetHeroStr(gg_unit_H000_0000, true)
      
        // Calculate the new strength
        set newStrength = currentStrength * 1.50

    call SetHeroStr(gg_unit_H000_0000, R2I(newStrength), true)
endfunction

//===========================================================================
function InitTrig_Dart_Transform takes nothing returns nothing
    set gg_trg_Dart_Transform = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Dart_Transform, GetOwningPlayer(gg_unit_H000_0000), "dd", true )
    call TriggerAddAction( gg_trg_Dart_Transform, function Trig_Dart_Transform_Actions )
endfunction
error.PNG
 
Are you using JassNewGenPack (it is likely the bundle you downloaded to get the editor with TESH integrated), and do you have JassHelper enabled?

The ability to declare global variables anywhere via the "globals" keyword is technically a vJass feature, so you would need JassHelper enabled for it. I don't remember exactly, but if you're using JassNewGenPack, there should be a menu in the toolbar labeled JassHelper or something similar where you can enable it.

If you're okay working off the latest patch though, then you could also consider using the default world editor and using an external editor (e.g. vscode) to write your code as Jass/vJass--or use Lua.
 

Deleted member 231919

D

Deleted member 231919

Thought I couldn't post because I got banned for no reason, but seems like I had to confirm my email. Weird. (Apologies to whoever received my email through "contact us")

Anyway,

I might not have the most recent TESH/jasshelper version, as I downloaded it probably years ago. I don't know if that matters or not.

I do have vscode installed, that is an interesting workaround.. thanks for letting me know. :)

Yeah, I tried enabling Jass Helper and the image attached is what happens:
jass helper error.PNG


I don't understand how I am having such a hard time getting global variables to work. It should be very simple. Also, I tried getting rid of the globals and endglobals block as chat gpt said TESH doesn't support that, but I have no idea if that is accurate or not.
 

Deleted member 231919

D

Deleted member 231919

It seems that you have two functions with the same name.
That is what the error says... but I checked the function names and I am pretty sure I don't.

function InitTrig_Dart_Transform

function Trig_Dart_Transform_Actions

These are the only functions. Is it a bug?

I couldn't even get udg variables to work.. I don't understand.
 
Last edited by a moderator:
Okay, seems like a step in the right direction.

I wonder if you accidentally put some code in the map header? (you can find it by clicking on the map name "Legend of Dragoon Tribute v0.01" in the trigger editor)

Because it looks like it still has some of your code left-over when you were trying it with udg_, which could explain the duplicate functions.

Your code that you posted in the first post should work correctly now. If not, maybe try with a new map just in case?
 

Deleted member 231919

D

Deleted member 231919

Okay, seems like a step in the right direction.

I wonder if you accidentally put some code in the map header? (you can find it by clicking on the map name "Legend of Dragoon Tribute v0.01" in the trigger editor)

That was exactly the reason! Thank you! It works now! I must have accidentally posted the code in the map header... and I haven't used the world editor in so long that I forgot you can put code in the map header..

Thanks for the help PurgeandFire and Rheiko!
 
Top