Raknet MAVs in a function

Blitz3D Forums/Blitz3D Beginners Area/Raknet MAVs in a function

Thrain(Posted 2016) [#1]
Hi, whenever I try to use the RN_SEND commands within a function it creates a MAV, if I use it within the main loop it will work, why is this?

; So this would work
Repeat

	If KeyHit(28)
		Print "sending message from server"
		chatMsg$=" Hello world!!! server here"
		chatMsg$ = Chr(ID_CHAT) + chatMsg
			; and now broadcast it
		ok = RN_Send(peer, chatMsg$, Len(chatMsg$) + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, True)
	EndIf

Until Keyhit(1)


; This wouldn't
Repeat
	
	UpdateNetwork()
	
Until KeyHit(1)


Function UpdateNetwork()
	If KeyHit(28)
		Print "sending message from server"
		chatMsg$=" Hello world!!! server here"
		chatMsg$ = Chr(ID_CHAT) + chatMsg
			; and now broadcast it
		ok = RN_Send(peer, chatMsg$, Len(chatMsg$) + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, True)
	EndIf
End Function



Dan(Posted 2016) [#2]
i guess, some of the variables arent configured as global ?
in that case, the function is accessing an empty variable instead of what it should, which is not the case in a normal loop.

maybe it is peer ?


Thrain(Posted 2016) [#3]
Thanks for the reply. I checked all the variables and all of them are either a global or constant.

However I figured it out; UNASSIGNED_SYSTEM_ADDRESS is 0 as a global, but when it's in the main loop it's value changed to 1715249224 and within the function it was also 0, so I have changed it so it retrieves the actual value of 1715249224.

If anyone else get's the MAV when working with RakNet he's what I did to fix it



; Use RN_GetUNASSIGNED_SYSTEM_ADDRESS() instead of UNASSIGNED_SYSTEM_ADDRESS


Function UpdateNetwork()
	If KeyHit(28)
		Print "sending message from server"
		chatMsg$=" Hello world!!! server here"
		chatMsg$ = Chr(ID_CHAT) + chatMsg
			; and now broadcast it
		ok = RN_Send(peer, chatMsg$, Len(chatMsg$) + 1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, RN_GetUNASSIGNED_SYSTEM_ADDRESS(), True)
	EndIf
End Function