• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

locals and being... wierd?

Status
Not open for further replies.
Level 7
Joined
Jul 30, 2004
Messages
451
maybe i'm missing the obvious, but i have this
XTEMP_n01 and XTEMP_n02 are defined as global integers, these locals are meant to overwrite that just in this trigger

Code:
JOURNAL UpdateBasic
    Events
    Conditions
    Actions
        Custom script:   local integer udg_XTEMP_n01
        Custom script:   local integer udg_XTEMP_n02
        Set XTEMP_n01 = 0
        Set XTEMP_n02 = 0
        //
        //some stuff here that doesn't matter
        //
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02))))
        Set XTEMP_n01 = 1 //normally this is a function, but its irrelevant, the function works
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02))))
        Set XTEMP_n02 = 8 //same here
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02))))
        //
        //more stuff that doesn't matter
        //

and the output i get?
(0 0) <-- thats ok
(1 1) <-- what?! shouldn't that be (1 0)
(8 8) <-- what again?! that should be (1 8)
 
Level 4
Joined
Nov 24, 2004
Messages
70
I have no clue, but i think you have to many '+'. You might wanna try just ((xtemp_no1)) + ((xtemp_no2)) instead of w/e u have right now. Other than that suggestion, I have no clue becasue I dont know what you want it to do exactly.
 
Level 7
Joined
Jul 30, 2004
Messages
451
xXx_burton_xXx said:
I have no clue, but i think you have to many '+'. You might wanna try just ((xtemp_no1)) + ((xtemp_no2)) instead of w/e u have right now. Other than that suggestion, I have no clue becasue I dont know what you want it to do exactly.

uhm, thats in the display part of the code... i could have xtemp_n01 + "whacky" + "weeeee" + "" + "" + "ok thats enough" + xtemp_n02 and all it would have in the end is

0whackyweeeeeok thats enough0
1whackyweeeeeok thats enough1
8whackyweeeeeok thats enough8

when those numbers should still be 0 0, 1 0, 1 8

and it doesn't matter what it needs to do, the point is xtemp_n01 is overwritten by an assign xtemp_n02 statement, which shouldn't be happening ever
 
Level 6
Joined
Feb 18, 2005
Messages
263
sry for my rudness, but you are a noob.

once you have defined a variable you may not redefine it.
therefore if you have a global variable NEVER define any other variable with the same name as you did in your code.

you said.
global integer xtemp_no1
global integer xtemp_no2

...

function foo
local integer xtemp_no1
local integer xtemp_no2

...

endfunction


this way you define the two variables 2 times. that courses bugs (or at least may do so)

if you want to use the xtemp_no* variables in your code do so. you do not need to define them as locals if they are already defined as globals...

sry for beeing rude, but if you use custom code be shure you understand what you aer doing!

- Raszul
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The reason for this bugging is YOUR NOT MEANT TO USE GLOBLES IN GUI and it only works due to its a bug and some say you can have only 1 local in gui triggers at a time.
If you want locals simply write your triggers in jass since for you to use the bug you need to know basic jass.
A global variable is stored as udg_ + the variable name.

Jass brings many benifits like less laggy spells and less leakage.
In jass you dont need to call the useless BJ calls as well as creat a function per condition.
You can use bugs like the handle vars to make even better multincastanious spells.

I recomend rather than using the GUI local bug you just write your triggers in jass where you can have as many locals as you wish.
 
Level 2
Joined
Aug 10, 2005
Messages
29
Try this:
If you want to use local integers, don't use globals. You are trying to take a global integer, and turn it into a local integer. This doesn't work, especially when you say to the program "I want to make a local integer called "global integer xtemp_n01" that already exists". This is just heading for trouble.

If you want to bring the value of XTEMP_n01 to a local integer, then do something like this. If you just want to make 2 temperary local integers, then just leave out the udg_ part. (udg = user defined global )

Code:
Code:
JOURNAL UpdateBasic 
    Events 
    Conditions 
    Actions 
        Custom script:   local integer XTEMP01 
        Custom script:   local integer XTEMP02
        Custom script:   XTEMP01 = udg_XTEMP_n01
        Custom script:   XTEMP02 = udg_XTEMP_n02 
        // 
        //some stuff here that doesn't matter 
        // 
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02)))) 
        Set XTEMP_n01 = 1 //normally this is a function, but its irrelevant, the function works 
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02)))) 
        Set XTEMP_n02 = 8 //same here 
        Game - Display to (All players) the text: ((String(XTEMP_n01)) + (    + (String(XTEMP_n02)))) 
        // 
        //more stuff that doesn't matter 
        //

Also, its good pracitce to set the variables back to 0 or null after you use them.

Code:
        Custom script:   XTEMP01 = 0
        Custom script:   XTEMP01 = 0
 
Level 7
Joined
Jul 30, 2004
Messages
451
lord raszul, the reason i want to define new variables under the same name is to use gui functions without having to convert every little thing to custom text, which is a pain in the butt cause i clearly don't wanna go search the API all day or make a new trigger and press convert for every function

and if you are further curious as to why i need to define a new set of locals, its because since i don't like to create tons of jass, i use triggers to simulate functions and use variables to simulate parameter passing, which, if there a lot of concurrent and overlapping trigger runs, can cause 'parameters' to become out of whack if they are not local to the trigger

well, i definately know a lot about programming and in other languages i have overwriten globals with locals with clear success especially when it takes function-scope-precidence over object-scope ie having to use this.variable for object-scope variables

clearly not redefining it, but creating a new variable under the same name, totally doable in non-jass

well in the end thats just plain anoying, cause i like to mix jass and gui since gui is a lot faster for looking up functions but the local variables are really nice and handy


and can everyone stop assuming i don't know the basics? i have a clear understanding of programming just not all these stupid bugs/details of JASS
ie dr super good, i know all that crap you can do with jass i use it all the time
and sven, setting primitive variables back to 0 is a waste of time (as i assume they will be destroyed at the end of the function), you only want to set reference variables to null to kill any remaining pointers
 
Level 7
Joined
Jul 30, 2004
Messages
451
alright, on second though i guess JASS isn't object oriented so it maybe doesn't have function scope and global scope, so maybe its considered redefining then -- not really sure i'm just used to programming in object oriented environment

by the way, i have another trigger that creates 3 local variables using the same name as global variables and that trigger works

so its pretty confusing as to why that happens
 
Level 9
Joined
Sep 8, 2004
Messages
633
I don't know jack about jass. All i'm good at is GUI triggers and in the time i've worked with the WE, i've found that often things simply don't work as they "should". Some fuctions just won't or don't work, and others sometimes do and sometimes don't, depending on various other variables. Try working around it, i've made a map with a huge amount of triggers (near 500) and few hundreds of variables, at least 30% of those are workarounds for problems i encountered and couldn't fix with the normal functions.
 
Level 7
Joined
Jul 30, 2004
Messages
451
Angelusz said:
I don't know jack about jass. All i'm good at is GUI triggers and in the time i've worked with the WE, i've found that often things simply don't work as they "should". Some fuctions just won't or don't work, and others sometimes do and sometimes don't, depending on various other variables. Try working around it, i've made a map with a huge amount of triggers (near 500) and few hundreds of variables, at least 30% of those are workarounds for problems i encountered and couldn't fix with the normal functions.

i did work around it, its just i'd rather not since in the end it can create more unforeseen problems
 
Status
Not open for further replies.
Top