generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Why am I exceeding the re-entrancy depth?

Previous Thread :: Next Thread 
tgp1994 is not online. tgp1994
Joined: 28 Aug 2007
Total Posts: 379
28 Sep 2012 11:45 PM
Hi everyone,

I'm having a weird issue where, when my tool is equipped, my onSelected function runs six times, then the script is terminated, with the output saying maximum event re-entrancy depth exceeded.

Looking at a snippet of my code,

me = nil --Tools are placed in the Character model when they're taken out, this variable must be set once the tool is taken out.
msg = nil

function onSelected(mouse)
print("Selected Local")
me = script.Parent.Parent
mouse.Icon = Cursor["gun"]
--mouse.Button1Down:connect(function() onButton1Down(mouse) end)
--mouse.Button1Up:connect(function() onButton1Up(mouse) end)
--mouse.Idle:connect(function() Idle(mouse) end)
--mouse.KeyDown:connect(keypush)
msg = Instance.new("Message")
msg.Parent = me
msg.Text = ""
print("Message placed in "..tostring(me))
end

bin.Equipped:connect(onSelected)


can anyone tell why this function is being repeated multiple times when it should only run once?
Report Abuse
Davidii is not online. Davidii
Joined: 17 Jul 2008
Total Posts: 1282
29 Sep 2012 07:52 AM
If it's a HopperBin you're using, I'm decently sure that it's bin.Selected:connect(onSelected).
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
29 Sep 2012 09:38 AM
The error occurs when you try doing something in en event that causes the event again which does something which causes it again, etc. until it errors.
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
29 Sep 2012 09:41 AM
While I can't see any reason that's happening, I do wanna give you a hint.

"me = nil --Tools are placed in the Character model when they're taken out, this variable must be set once the tool is taken out."
If it's a character you're looking for, you can get that at any time. Given that you're accessing mouse, this script *must* be local (or a script in a hopperbin which is treated as a local script anyway). In this case, you can simple do the following:

me = game.Players.LocalPlayer.Character;
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
29 Sep 2012 09:42 AM
Oh, as for debugging: place that script in a local script all of its own and put it in the tool. Tell me if any error occurs.
Report Abuse
tgp1994 is not online. tgp1994
Joined: 28 Aug 2007
Total Posts: 379
29 Sep 2012 10:35 AM
Thanks for the replies everyone,

@davidii: It used to be a hopperbin, but I felt the need to port it over to a Tool instead... Should I just keep it as a hopperbin? I almost felt like hopperbins were being phased out by roblox since I would get several script errors from a roblox GUI script saying that the hopperbins didn't have a ToolTip property.

@blobbyblob: Sorry for my lack of information, it actually was just a script-script, and not a LocalScript. Apparently hopperbins work a little differently :\ I tried moving the code over to a local script, and after removing the first script and running my game:

Selected
About to set parent...
Selected
About to set parent...
Selected
About to set parent...
Selected
About to set parent...
Selected
About to set parent...
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
Selected
About to set parent...
11:28:20 - maximum event re-entrancy depth exceeded
11:28:20 - maximum event re-entrancy depth exceeded
Parent set.

The script appears to have functioned a little bit differently than it did before, although with a similar (and undesirable) output. Since I had placed in some debugging statements since I've last pasted my code, here is the new version:

function onSelected(mouse)
print("Selected")
me = script.Parent.Parent
mouse.Icon = Cursor["gun"]
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Button1Up:connect(function() onButton1Up(mouse) end)
mouse.Idle:connect(function() Idle(mouse) end)
mouse.KeyDown:connect(keypush)
msg = Instance.new("Message")
msg.Text = ""
print("About to set parent...")
msg.Parent = game.Workspace.Player1
print("Parent set.")
print("Message placed in...")
printHiearchy(msg)
end
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
29 Sep 2012 10:38 AM
well if you are continously parenting something to another thing, the script will keep on firing the select function whenever it parents since it "re-runs".

hurrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.
Report Abuse
Anaminus is not online. Anaminus
Top 100 Poster
Joined: 29 Nov 2006
Total Posts: 5945
29 Sep 2012 10:39 AM
It's a bug. If you use Equipped to immediately put something in the character, then the Equipped event fires again, which immediately puts something in the character, which fires the Equipped event, which immediately puts something in the character...

A simple fix is to add a wait to the beginning, or debounce it in some way.
Report Abuse
tgp1994 is not online. tgp1994
Joined: 28 Aug 2007
Total Posts: 379
29 Sep 2012 10:50 AM
@Anaminus: I figured it was some sort of bug :\ Thank you for your help, I shall try debouncing it.
Report Abuse
tgp1994 is not online. tgp1994
Joined: 28 Aug 2007
Total Posts: 379
29 Sep 2012 07:18 PM
Just wanted to let everyone know: The debounce is more trouble than you have to go through, simply putting a wait(0) statement at the beginning of the function does wonders. Thanks again everyone!
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
29 Sep 2012 09:30 PM
The wait 0 may still fail from my experience.

The safest way to fix it is to put the code in a new thread:

hopperbin.Selected:connect(function()
Spawn(function()

..equipped handling

end)
end)
Report Abuse
tgp1994 is not online. tgp1994
Joined: 28 Aug 2007
Total Posts: 379
29 Sep 2012 10:38 PM
Thank you for the tip, I'll change it that!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image