• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Internet enabled features crash when theres no connection

772
Posts
13
Years
  • Age 35
  • UK
  • Seen Mar 26, 2024
Is there a way to check for an internet connection before doing things such as mystery gift. When i try to access such features with no internet connection i get an error

Exception: NoMethodError
Message: undefined method `size' for nil:NilClass
Sockets:368:in `connect'
Sockets:510:in `initialize'
Sockets:586:in `new'
Sockets:586:in `pbHttpRequest'
Sockets:562:in `pbPostData'
PokemonLoad * Edited:379:in `pbStartLoadScreen'
DebugIntro:6:in `main'
Main:37:in `mainFunctionDebug'
Main:15:in `mainFunction'
Main:15:in `pbCriticalCode'

Ideally i'd like for it to just say something along the lines of an internet connection is required, but at the moment it just crashes
 
453
Posts
10
Years
  • Age 32
  • Seen Mar 23, 2024
If you take a look at the Sockets script, line 368, you'll see there's a call to SocketError.check in case of an error (e.g., no internet connection). The check method raises the error, and that means that you can catch it when you connect, i.e., when you create a socket.

Here I gave a script to an NPC that connects to a closed port on the local machine. The error should be similar, if not the same, to the one that gets raised when there's no internet connection.

socket = TCPSocket.new("127.0.0.1", 9999) rescue nil
if !socket
p("Cannot connect!")
end

In case of failure, the socket will get the value 'nil'. The "rescue nil" statement at the end will catch the error and assign 'nil' to the socket instead. We test for that and if it's true, we print out a message. p("something") will make a pop-up window with the message you provide. Now you can customize this to suit your needs.
Hope this helps!
 
401
Posts
19
Years
  • Age 29
  • Seen Dec 4, 2016
If you take a look at the Sockets script, line 368, you'll see there's a call to SocketError.check in case of an error (e.g., no internet connection). The check method raises the error, and that means that you can catch it when you connect, i.e., when you create a socket.

Here I gave a script to an NPC that connects to a closed port on the local machine. The error should be similar, if not the same, to the one that gets raised when there's no internet connection.

socket = TCPSocket.new("127.0.0.1", 9999) rescue nil
if !socket
p("Cannot connect!")
end

In case of failure, the socket will get the value 'nil'. The "rescue nil" statement at the end will catch the error and assign 'nil' to the socket instead. We test for that and if it's true, we print out a message. p("something") will make a pop-up window with the message you provide. Now you can customize this to suit your needs.
Hope this helps!
This works but Ruby provides a better approach that allows you to skip the if block:
Code:
begin
  socket = TCPsocket.new('127.0.0.1','3000')
rescue
  print 'failed to connect to 127.0.0.1:3000'
end

rescue can take arguments which equate to the error being raised. You will have to check at http://www.ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/Socket.html for the specific error as its different foreach system. You'll want to use the ones for Windows when using RMXP. You can then print the specific error message:

Code:
begin
  socket = TCPSocket.new('127.0.0.1','3000')
rescue Errno::ECONNREFUSED => e
  print e.message
end

This would print the message "the target sockaddr was not listening for connections refused the connection request". This way of handling errors is great as it allows you to catch certain exceptions yet let others be fatal to the program (i.e allow the program to crash). You wouldn't want the game to crash if the connection was refused but you might want to let the game crash if there is a fatal ruby error that occurs during the creation of the socket (unlikely but you must take it into consideration)
 
Last edited:
Back
Top