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.

AppGameKit Studio Chat / Arrays in Functions

Author
Message
huggy70
3
Years of Service
User Offline
Joined: 11th Jun 2020
Location:
Posted: 10th Jun 2023 20:01 Edited at: 10th Jun 2023 22:27
Hi,

I am a little irritated by the way how arrays in functions seem to work in AGK. I cannot find sth. in the help files, so perhaps can someone confirm or give a hint whats going on:

in a function all arrays seem to be global variables is that correct?
so when I call these 2 simple functions when I call test1() and then test2() then x in test2() will be set to a value of '50'!



So how to get local arrays with scope only inside the function?
I need to do some recursive function calls with arrays
huggy70
3
Years of Service
User Offline
Joined: 11th Jun 2020
Location:
Posted: 10th Jun 2023 20:16
ok, I think the DIM command is declaring an array as global, the following seems to work:

Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 16th Jun 2023 18:34 Edited at: 16th Jun 2023 18:36
Dim is always global, it's stated as such in the command / language guide

Have you thought about using MemBlocks instead? ( just a suggestion as I'm not sure what you are doing with the functions )
huggy70
3
Years of Service
User Offline
Joined: 11th Jun 2020
Location:
Posted: 17th Jun 2023 14:47 Edited at: 17th Jun 2023 14:47
Quote: "Dim is always global, it's stated as such in the command / language guide"

well I had a look here: https://www.appgamekit.com/documentation/language/5_dim.htm and there seems to be no mention being global.
In the command reference of my AGKS installation the DIM command is not listed.

Quote: "Have you thought about using MemBlocks instead? ( just a suggestion as I'm not sure what you are doing with the functions "

I'm on the way doing a chess engine, this array contains the valid moves as part of a recursive alphabeta score function, so each array would have approx 20 to 40 entries each by now. With a search depth of 3 ( the max I tried by know, a depth of 4 takes approx 20 minutes per move in AppGamekit) there are some 60.000 values for all move lists. Once all works to my satisfaction i will be looking into optimization perhaps memblock could do me some good there? I don't know.

When ready I want to port the engine to c++, Appgamekit is fun because I want an App for mobile devices and I have no clue how to do this with c++ . I also want to do a port for Amiga using AMOS, because it should be easily portable from Appgamekit

Thanks for your comment
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 17th Jun 2023 14:59 Edited at: 17th Jun 2023 14:59
Hi,

It's in 'principles' - 1_datatypes - "All arrays are created as global arrays"

Admittedly it's well hidden

Sounds like an interesting project and now I understand the need for it to be recursive.
huggy70
3
Years of Service
User Offline
Joined: 11th Jun 2020
Location:
Posted: 17th Jun 2023 15:39
Quote: "It's in 'principles' - 1_datatypes - "All arrays are created as global arrays""

ahh, really. That is a part I must admit I would never have looked
This part gives the impression arrays are always global. So I found out by accident. Could be confusing

Quote: "Sounds like an interesting project and now I understand the need for it to be recursive."

Thanks. I must admit I am kind of a lousy player and I always wanted to do this and compete in the global chess engine list. There seem to be hundreds of engines around, even really bad ones, so chances are not bad to get a decent ranking perhaps
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 17th Jun 2023 20:10 Edited at: 17th Jun 2023 20:11
Hi,

Memblocks are pretty easy and just as simple as using an array...

Here's some code I was playing with earlier today..



Obviously this would be local to the function, bit like malloc etc..
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 18th Jun 2023 02:39
Personally, I prefer Backgammon.
huggy70
3
Years of Service
User Offline
Joined: 11th Jun 2020
Location:
Posted: 18th Jun 2023 10:30
Quote: "Memblocks are pretty easy and just as simple as using an array..."

thanks, will have a look into it.

Meanwhile working with arrays I found some other curiosity: when using the .Length function of an array it will return actually length-1 of the array.
So when there is 1 element in an array it will return a length of 0. This is odd and will make porting to other languages quite challenging, lol
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 19th Jun 2023 03:39

That would suggest that .length is returning the last position of the array, rather than the actual number of elements - ( sizeof )





blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Jun 2023 06:25 Edited at: 19th Jun 2023 06:26
Quote: "That would suggest that .length is returning the last position of the array, rather than the actual number of elements"


Yes that's correct. Once I started referencing this way I found any other way annoying and cumbersome
nonom
6
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Picking mushrooms
Posted: 22nd Jun 2023 17:46 Edited at: 22nd Jun 2023 17:47
I would like suggest using arrays of types.
http://www.nyan.cat/index.php?cat=pirate

Login to post a reply

Server time is: 2024-05-03 06:38:14
Your offset time is: 2024-05-03 06:38:14