• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Transfer locals ? ( integer i)

Status
Not open for further replies.

Ardenian

A

Ardenian

How do I transfer locals ?

I tried to
  • set g = h
,both being integer locals, but apparently it does not work.

Trigger 1 has a
  • local integer h
This integer value should be transferred to a second trigger with
  • local integer g
1. Do I need different local names ?
2. If I use the same name, is it transferred ? The second trigger runs within the first one
/ If I create both locals g and h in the second trigger, would it transfer the value of h in the second one ?

My approach would be to store the values in variables, but I need to transfer a lot of data from one trigger to another using locals.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You seem to not understand what locals really are.
You don't have access to my local variables.
You don't know what my local variables are.
You don't even know if I even have local variables.

However, to copy and paste them, you can set a global variable to be equal to the local variable and then load the global variable inside the other trigger/function.
 

Ardenian

A

Ardenian

Locals are 'temporary variables', as far as I understand.

Alright, thanks.
 
Level 15
Joined
Sep 29, 2008
Messages
363
Ardenian

Local variables only "exist" into the function scope where you declared them.
to extract local values you could use global variables (as Wietlol says) or store them into a hashtable (object attach) or return them as function response.
Local variables never work outside the function where they were created, you dont need to extract this variable, you need to extract its value.
 
That's actually the positive part about locals. They don't interfere with stuff outside the function, so they are safer.

You can name them "u" in function f1 and also name an other one "u" in function f2. A local only exists inside a function.

If it should interact with other code it needs to be stored into global variables, hashtables, or given as function parameter.

Is there a specific problem you have to solve there with it?
 

Ardenian

A

Ardenian

Oh, thank you for the explanation!

I wanted to create a trigger only using locals which is, now obviously, not possible if I would like to transfer data between different triggers or loops/...

That's a bit Off-Topic, but a trigger using locals, should it majorly use locals if possible or is it okay to create globals although I could use locals instead on specific parts ( to guarantee some readability ?)
 
In GUI locals can/should (only) be used to better use some JASS functions. Else in GUI global "temp variables" is the way to go.
Locals are good, but GUI should stay as most GUI as possible.
So use them only if needed. (my personal oponion though)
Don't kill me GUI-JASSER out there. :cute:

In JASS there is an other maxim.
Using locals over globals is good practice here to achieve autonomous code and more safety.

In case you want to learn plain (v-)JASS I would be glad to introduce you in case you are interested one day. :csmile:
 

Ardenian

A

Ardenian

Ahh, I understand, thanks! Oh damn, that ruins my new system :/ I use locals all over the place in GUI.

Hm, I think the only think I need to understand before being able to move to Jass are events. I don't get how they work.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
13-15 in this tutorial covers triggers.


http://www.hiveworkshop.com/forums/graveyard-209/video-tutorial-series-vjass-220853/



The best way to think of a function is that a function is a list of instructions that states how to do a task.

Suppose I have a task called "Write Hello"

I have 5 people that need to do this task. I give them each a pencil. They each write hello. They each give the pencil back.

If I were to write such a function in JASS

JASS:
function WriteHello takes Pencil pencil, Person person returns nothing
endfunction

Pencil pencil and Person person are both local variables. They are a little bit more special though. They are arguments to a function. An argument is something that I can specify when I run that function.

When I had 5 people do my task, I called the function 5 times. Each time, I stated which person would write Hello and I gave that person a pencil.

When they finish writing Hello, the function ends. These local variables also go away. They give me back the pencil and they are no longer specified by my task to write Hello : p.

Each person has their own pencil. They can't use the pencil of another person. In the world of programming, they can't even see the task another person is doing. It'd be like they'd all be in their own separate interrogation rooms. When I start the function, I put the person and the pencil in their own interrogation room. I'd have a monitor in each room that shows the task they need to do. Each room would be the execution of the function. The rooms can't see what the other rooms have in them. They all run independently. The task, writing hello, would be the instructions that each room is running. They all read from the same set of instructions.


Hopefully this explains to you what local variables are ^_^.
 

Ardenian

A

Ardenian

Yes, thanks a lot, that explains it perfectly!

Two questions pop up for me, after a local is created while one person is writing, then the pencil will not change. What I try to say, If I have a loop, for example, from 1 to 10 and I create local a as first line within this loop, will the local a newly created each time or will it keep its previous value ?

Example:
Loop from 1 to 2
First line of action is local integer i, last one is set i = i +1

If it was initially 0 and is one at the end of the first run, will it be 1 at the beginning in the second run or will it be newly created ?

Second question, about functions:

JASS:
function DoubleInteger takes int udg_TempInteger returns int udg_TempInteger*2
endfunction

Is this correct or would it be:

JASS:
function DoubleInteger takes int udg_TempInteger returns udg_TempInteger*2
endfunction

I am not sure whether I have to add int in the returns part. In your C++ tutorial there is only 'takes int number returns 2*number'.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
JASS isn't C++ : D. The portion of the tutorial is up doesn't cover returning yet either ; P. The returns refers to the return type. Remember how all variables have a type?

JASS:
function DoubleInteger takes integer myValue returns integer
    return myValue*2
endfunction

Setting a variable is not the same as declaring a new variable

JASS:
// declaration
local integer i

// assignment
set i = 5
set i = i + 6
set i = 22
 

Ardenian

A

Ardenian

Oh hell, each language is different :/

Alright, thanks, now it is clear!
 
Status
Not open for further replies.
Top