Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How do i define local arrays in a function

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Dec 2015 00:34 Edited at: 22nd Dec 2015 00:48
i have to following code


it is not recognizing the layers$[] array. the output looks like;


How do i define the layers$[] array so this will work. I don't want to have to make it global (when i make it global it sees the array)
GunnerJnr
AGK Developer
8
Years of Service
User Offline
Joined: 30th Nov 2015
Location: Bridgwater, UK
Posted: 22nd Dec 2015 09:53 Edited at: 22nd Dec 2015 09:54
If you scroll near the bottom there are a couple sections on using arrays in functions, hopefully this will help, cheers.

Click Me!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Dec 2015 11:21
you can use the keyword LOCAL but I don't know if this will solve the problem.
You also have 3 lines that don't even print the element number. Have you used layer$ anywhere else in your program?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Dec 2015 11:48
i'm sorry i just copied the code from a larger program. you can fix the syntax issues but the problems remain.
just tell me how i can define an array that is local to a function
GunnerJnr
AGK Developer
8
Years of Service
User Offline
Joined: 30th Nov 2015
Location: Bridgwater, UK
Posted: 22nd Dec 2015 15:42
Quote: "just tell me how i can define an array that is local to a function"


Wow that sounds a bit demanding and rude, perhaps a please on the end wouldn't go a miss
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Dec 2015 16:25
The help files say that arrays in V2 are backwardly compatible. That means they will always be global.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Dec 2015 21:45
Quote: "Wow that sounds a bit demanding and rude, perhaps a please on the end wouldn't go a miss "

it does sound very rude and i apologize sincerely. thank you all for the help
GunnerJnr
AGK Developer
8
Years of Service
User Offline
Joined: 30th Nov 2015
Location: Bridgwater, UK
Posted: 22nd Dec 2015 21:49
Nice one dude, no worries. I gathered you didn't mean it maliciously in any case, but reading it back it does sound a bit demanding haha.
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 23rd Dec 2015 23:24
You can have local arrays, but for some reason you can't assign values to them on the same line they are defined like you can with global arrays. (Possibly a bug)

Your code is defining a local array, but failing to set any values to it because of this. If you set a value in the array on a separate line it's value will show.

eg:

function test_function()
layers$ as string[4] = [ "o", "b", "r", "s", "h" ]
layers$[1] = "B"
layer as integer

for layer=0 to layers$.length
print(str(layer)+"."+layers$[layer])
next
endfunction
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Dec 2015 23:34
Useful info, thanks
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Jan 2016 04:40
thank you very much mike. very useful

Login to post a reply

Server time is: 2024-04-25 15:27:18
Your offset time is: 2024-04-25 15:27:18