Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright i fixed the issue. The issue was that i was retrieving the objects from another arraylist. So imagine you have an ArrayList called A. And another called B. So imagine you are retrieving Objects from ArrayList A and Moving them across into B. If i retrieve the same object from A twice and moving it into B, inside B the two objects will have the same hashCode which will cause problems. </p> <p>So to fix that, i made a new bridging object that inherits all of the values from objects coming out of a and then passing the new object into B instead of directly moving A's objects. I did this like so:</p> <pre><code>public Perk getPerk(ArrayList&lt;Perk&gt; perks) { Perk tempPerk = new Perk(); Perk newMPerk = new Perk(); ArrayList&lt;Perk&gt; tempPerks = new ArrayList(); tempPerks.clear(); int random = Menu.randInt(1, 100); for (int i = 0; i &lt; perks.size(); ++i) { if (hasRar(perks.get(i), random)) { tempPerks.add(perks.get(i)); } } if (tempPerks.isEmpty() == false) { int nextRandom = Menu.randInt(0, tempPerks.size() - 1); tempPerk = tempPerks.get(nextRandom); newMPerk.name = tempPerk.name; newMPerk.cost = tempPerk.cost; newMPerk.rarity = tempPerk.rarity; newMPerk.minusDec = tempPerk.minusDec; newMPerk.plusInc = tempPerk.plusInc; newMPerk.rewardBonus = tempPerk.rewardBonus; } else { Perk newPerk = new Perk(); newPerk.name = "Extra"; newPerk.cost = 0; newPerk.rarity = 1; newPerk.minusDec = 0; newPerk.plusInc = 0; newPerk.rewardBonus = 0; newMPerk = newPerk; } return newMPerk; } </code></pre> <p>So NewMPerk inherits all of teh variables: Name cost etc. From the Object that is retrieved from Array List A. And then it is returned and added into Array List B. Since NewMPerk is a new Object of the type Perk, it will have a different hashCode everytime.</p> <p>Hope this can help other people :) </p> <p>If you have any questions feel free to ask :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload