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 / Online doc example 'CreateBroadcastListener' no longer working

Author
Message
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 4th Apr 2018 10:40
The example code on: https://www.appgamekit.com/documentation/Reference/Multiplayer/CreateBroadcastListener.htm is giving 2 errors:

Quote: "
Running C:\Program Files (x86)\The Game Creators\AGK2\Tier 1\Compiler\AGKCompiler.exe (in directory: D:\Install\Appz\Programming\AGK\_Projects\_My Projects\MultiPlayer & Networking\Host & Join\Broadcast Listener)
main.agc:56: error: Array has already been defined with a different type, types must match
main.agc:77: error: Array has already been defined with a different type, types must match
Compilation failed.
"

TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 4th Apr 2018 13:04
Go to those two lines and change the dim statements to read dim networkNames[networkListSize] as NetworkName. Probably would be a good idea to change it in the manual as using arrays have changed in AGK2.
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 4th Apr 2018 17:23 Edited at: 4th Apr 2018 17:33
@TomToad
I know, you're absolutely right. This works perfectly fine:



I was overthinking it and tried the 'new and improved' array/type handling way, which is a bit different when defining and adding/removing elements from the array. Such as:
networkNames as NetworkName[] // declaration empty array new style.
networkNames.length = networkListSize // change size of the array new style.

But that's somehow didn't work as well, need to dive back into docs I guess.

Many thanks.
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 5th Apr 2018 14:52 Edited at: 5th Apr 2018 15:06
Hmm. Still couldn't stand the idea that I apparently can't fully get my head wrapped around the type array new definition thing..

dim networkNames[0] as NetworkName I get this is the old obsolete way, so does no longer work.

dim networkNames[networkListSize] as NetworkName As suggested by TomToad and works fine, but from the manual I (mis?)understood this for backwards compatibility only and that the new style of declaring an array is:

networkNames as NetworkName[networkListSize] but that's not working for arraysize must be constant or literal integer.

So I resorted to:
networkNames as NetworkName[] for declaration empty array new style, so far so good.

But then when I hit this part..


I'm getting an error:
if networkNames[c].name$ = networkName$ I'm getting an error: "networknames" has not been defined as an array



So.. I'm kinda puzzled here. I've used type arrays before, but not in this fashion and don't understand why doesn't work. If anybody has an idea, please let me know?

Full code below:
puzzler2018
User Banned
Posted: 5th Apr 2018 14:59
Dont we have to use .insert for empty arrays?

Perhaps something like this






TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 5th Apr 2018 15:55 Edited at: 5th Apr 2018 15:56
Old style arrays are global by default. New style arrays are local unless declared global. The code below will work. Using Global networkNames as networkName[0] to define the array and networkNames.length = networkListSize to resize the array.

You can also make the array local and pass the array to the function through a reference
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 5th Apr 2018 18:08 Edited at: 5th Apr 2018 18:21
Aargghhhh... Of course: hence the error message! I couldn't understand why worked in other apps I've been using type arrays in.
Again many, many thanks. \o/

At the TGC/AGK moderator(s):
1) Time to update the example docs. I've posted the change.
2) Pity we can't change the topic title and add [solved] to it. Perhaps an additional button to add it as a string?
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 5th Apr 2018 21:00
Update:
The fixed version has been approved and now part of the online docs here: CreateBroadcastListener

I've once again requested a badge for you TomToad, for this the 3rd(I believe) contribution to the official AppGameKit docs.

Btw: thanks for thinking along puzzler2018.


Login to post a reply

Server time is: 2024-04-26 05:31:52
Your offset time is: 2024-04-26 05:31:52