Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user5200 · Aug 10, 2012 at 04:45 AM · c#guierrorhashtablechain reaction

Causing a chain reaction and hashtable errors

Hi,

This is somewhat of a followup to my previous question here:

http://answers.unity3d.com/questions/277793/toggling-multiple-button-states.html

It is not about the same topic but I am working on the same UI elements. Of course, I will try to explain my problem so that no background reading is required. Well, here we go!

Project description

I'm making a visual GUI for my game's stat upgrade system. Basically, there is a 7x10 grid of GUI.buttons with no texture on them. Gridcontent info is stored in a 2D array that correspond to the location of the node on the grid. The user is meant to place his/her desired stat blocks on the grid to enhance the power of the main character. But there's more!

Blocks of the same stat can chain together creating "power waves" that originate from a central Generator. Chaining together these stats will create a multiplier effect. For example, think of a match-3 style puzzle game where you have to match the colors of blocks. Except that, the direction of the power wave matters as well.

Progress so far

I am on the final stage of the visual implementation of this idea and I am having trouble creating a chain reaction effect. Since the power wave originates from the generator, the user can put similar blocks next to each other but they will not chain unless they are connected to the generator. Once you do connect them to the generator, there should be some kind of chain reaction effect which spreads the power wave among all the connected nodes.

Here is the code I have so far

 if (GUI.Button(new Rect(314, 126, 22, 22), texturestoapply[0], mystyle))
  {
  if (Event.current.button == 1 && texturestoapply[0] != null)
  {
  Storepotential(new Vector2(1,1), 0);
  removemsg = true;
  }
  if (clickedon == null)
  return;
  if (clickedon == "upwards" || clickedon == "downwards" || clickedon == "leftwards" || clickedon == "rightwards")
  {
  Changewave(clickedon, 1, 1);
  updateAdjacentnodes(1,1);
  Clearallmouseshit();
  return; 
  }
  texturestoapply[0] = textureinsidemouse;
  gridcontent[1,1] = clickedon;
  checkAdjacentnodes(1, 1);
  Chainreaction();
  }

Above is an example of one of the buttons on the grid. Once you have chosen a stat, you can place it on the grid (click on the button) and it will place the approptiate texture on the button. Also it will immediately check the adjacent nodes to see if it can make any power wave connections.

 void checkAdjacentnodes(int gridlocationx, int gridlocationy)
  {
  //desclaring adjacent nodes
  string abovenode, rightnode, belownode, leftnode;
  Vector2 aboveloc, rightloc, belowloc, leftloc;
  
  //finding the adjacent nodes
  abovenode = gridcontent[gridlocationx, gridlocationy - 1];
  aboveloc = new Vector2 (gridlocationx, gridlocationy - 1);
  rightnode = gridcontent[gridlocationx + 1, gridlocationy];
  rightloc = new Vector2 (gridlocationx + 1, gridlocationy);
  belownode = gridcontent[gridlocationx, gridlocationy + 1];
  belowloc = new Vector2 (gridlocationx, gridlocationy + 1);
  leftnode = gridcontent[gridlocationx - 1, gridlocationy];
  leftloc = new Vector2 (gridlocationx - 1, gridlocationy);
  
  //Find out the current wave direction through gridcontent
  string currentwave = gridcontent[gridlocationx, gridlocationy];
  //Find out what the stat is and clears the mouse "clipboard"
  string currentstat = Queryforstats(gridlocationx, gridlocationy);
  
  //generator check
  if (abovenode == "generator")
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwavedown";
  }
  
  if (rightnode == "generator")
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveleft";
  }
  
  if (belownode == "generator")
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveup";
  }
  
  if (leftnode == "generator")
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveright";
  }
  
  
  
  if (currentstat == "spd")
  {
  //check for adjacent active powerwaves
  if (abovenode == "powerwavedown")
  {
  //if its the same stat then you can continue the wave
  if (spdnodes.Contains(aboveloc))
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwavedown";
  }
  }
  
  if (rightnode == "powerwaveleft")
  {
  //if its the same stat then you can continue the wave
  if (spdnodes.Contains(rightloc))
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveleft";
  
  }
  
  
  }
  
  if (belownode == "powerwaveup")
  {
  //if its the same stat then you can continue the wave
  if (spdnodes.Contains(belowloc))
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveup";
  }
  }
  
  if (leftnode == "powerwaveright")
  {
  //if its the same stat then you can continue the wave
  if (spdnodes.Contains(leftloc))
  {
  gridcontent[gridlocationx, gridlocationy] = "powerwaveright";
  }
  }
  
  //check for adjacent nodes of just the same thing but no waves
  if (leftnode == "spd")
  gridcontent[(int)leftloc.x, (int)leftloc.y] = currentwave;
  if (rightnode == "spd")
  gridcontent[(int)leftloc.x, (int)leftloc.y] = currentwave;
  if (leftnode == "spd")
  gridcontent[(int)leftloc.x, (int)leftloc.y] = currentwave;
  if (leftnode == "spd")
  gridcontent[(int)leftloc.x, (int)leftloc.y] = currentwave;
  }
  
  
  }

 string Queryforstats(int gridX, int gridY)
  {
  if (speedon)
  {
  spdnodes.Add(new Vector2(gridX, gridY));
  Clearallmouseshit();
  return "spd";
  }
  
  if (strengthon)
  {
  strnodes.Add(new Vector2(gridX, gridY));
  Clearallmouseshit();
  return "STR";
  }
  
  if (viton)
  {
  vitnodes.Add(new Vector2(gridX, gridY));
  Clearallmouseshit();
  return "vit";
  }
  
  return null;
  
  }

What we have above is the function that checks adjacent nodes and a helper function that queries the current node to see what stat has been added to the grid. If both the stat type and power wave direction match with their peers, it will continue the power wave.

 void Chainreaction()
  {
 
  foreach (Vector2 gridloc in spdnodes)
  {
  updateAdjacentnodes((int)gridloc.x, (int)gridloc.y); 
  
  }
  
  foreach (Vector2 gridloc in strnodes)
  {
  updateAdjacentnodes((int)gridloc.x, (int)gridloc.y); 
  }
  
  foreach (Vector2 gridloc in vitnodes)
  {
  updateAdjacentnodes((int)gridloc.x, (int)gridloc.y); 
  }
  
  Debug.Log("firstsquare: " + gridcontent[1,1].ToString() + "\n secondsquare: " + gridcontent[2,1].ToString());
  
  }

This above function is the one that I am struggling with. What I want it to do is check all the nodes on the grid that have a stat block placed on them. And then, check each of THEIR adjacent nodes to see if there are latent connections that can be made. Like when THAT PERFECT BLOCK falls into the perfect place in a match 3 game. Something like this:

http://www.youtube.com/watch?v=56CS2b89pLI

InvalidOperationException: Hashtable.Enumerator: snapshot out of sync.

I am also getting this error but I am not sure whether or not it is stopping the execution of something I have coded. I am also unsure where the error is originating from.

If anyone has any ideas about how to do this better or where the error is coming from, I would love to hear it!

Thanks for reading.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is networkbehaviour underlined in green? 1 Answer

3 Days and I still can't figure out c# reflection, please help? Trying to use a protected Type and method. 1 Answer

"NullReferenceException" while trying to draw a texture (C#) 1 Answer

Is there something wrong with my c# script? 1 Answer

Displaying a static variable from another script with OnGUI 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges