arrays... lose info ?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

arrays... lose info ?

Post by Chrius » Tue May 17, 2011 5:14 pm

Hi all,

I couldn't find a solution to my problem...
I have an array, which i tried to declare as global in preopen stack (i've tried without too)

Code: Select all

on openstack
   global aTabPre
end openstack
then, i have a push button with this code :

Code: Select all

on mouseUp
  put url("binfile:" & tDatabasePath & "\myfile.txt") into sContenu
     put 0 into nLinecounter
      repeat for each line tLine in sContenu
      add 1 to nLinecounter
     put item 1 of tLine into var1
     put item 2 of tLine into aTabPre[nLinecounter]
     end repeat
end mouseup
So now, i have the result i want... My item 2 is in an array, and it works fine when i look at any result just after the repeat...

Code: Select all

answer aTabPre[2] with ok
But when i try to look at this array, with another button, it's empty...

I guess it is a global definition problem ? But i can't see what's wrong
I could do the repeat code each time i would need, but i'm sure we can avoid this by just keeping the array, no ?

Thanks for help

Chris

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: arrays... lose info ?

Post by BvG » Tue May 17, 2011 5:26 pm

A global needs to be declared in each scopte that uses it. That means declaring it on openstack doesn't actually do anything. Instead, you must add the line "global aTabPre" to each button. You can declare variables outside of handlers. So for example, a script could look like this and work:

Code: Select all

global aVariable
on mouseUp
add 2 to aVariable
end mouseUp

on mouseDown
put aVariable
end mouseDown
See also the documentation pdf about variables and containers for more info on this.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Chrius
Posts: 19
Joined: Fri Jan 28, 2011 4:04 pm

Re: arrays... lose info ?

Post by Chrius » Tue May 17, 2011 5:59 pm

Thank yoouuu !!

it works fine now :)

Post Reply