Register | Login
Forum Index > Requests and Feedback > static variable in function
Author Message
Pages: 1
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[156] static variable in function - posted: 2011-10-27 19:18:39

does Ziron support static variable inside the function or procedure ?

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[157] - posted: 2011-10-27 19:40:18
what do you mean by static variables? global variables inside function? if yes then..

Code:
procedure myProc1() {
  global int32 myInt;

  myInt = 100;  
  
  return myInt;
}

procedure myProc2() {
  global int32 myInt;

  //nothing changed in this func, myInt should be 0 since it is not related to myProc1 myInt
  
  return myInt;
}

eax = myProc1();
print('myProc1: ', eax:int, '\r\n');
eax = myProc2();
print('myProc2: ', eax:int, '\r\n');


each global inside a function will have their own version of myInt in a local scope.

the output should be:

Code:
myProc1: 100
myProc2: 0


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[158] - posted: 2011-10-27 19:42:13
well , that waht i am asking for.

thanks.


http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[159] - posted: 2011-10-27 19:46:37
maths functions such as add and so on need some work but another example

Code:
procedure myProc1() {
  global int32 myInt;
  
  //maths functions need work which i will do very shortly, for now simple mov add mov.
  eax = myInt;
  eax += 100;
  myInt = eax;
}

procedure myProc2() {
  global int32 myInt;

  //nothing changed in this func, myInt should be 0 since it is not related to myProc1 myInt
  
  return myInt;
}

eax = myProc1();
print('myProc1: ', eax:int, '\r\n');
eax = myProc2();
print('myProc2: ', eax:int, '\r\n');
eax = myProc1();
print('myProc1: ', eax:int, '\r\n');


output:
Code:
myProc1: 100
myProc2: 0
myProc1: 200


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[160] - posted: 2011-10-27 19:52:38

does #define directive works as in C&C++ , so i what to use static instead global statement?

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[168] - posted: 2011-10-27 20:32:25
static keyword is reserved for something else, that once it is corrected will be explained in detail via documentation.

and the #define keyword works different to c and c++, it only accepts a single parameter (for now)

#define ABC;
#define 1234;

check documentation via the menu for directives.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 9 user(s) online. 0 member(s) and 9 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd