- Home /
Cannot implicitly convert type 'int' to 'bool' error CS0029
Need some help with my script getting compiling errors. Not very good with C#
//Updates the shop display texts
private void UpdateShopDisplay (){
//Update texts
coinAmmount.text = SaveManager.coinAmmount.ToString();
ShopOwnedItems[0].text = SaveManager.extraSpeed.ToString();
ShopOwnedItems[1].text = SaveManager.shield.ToString();
ShopOwnedItems[2].text = SaveManager.sonicWave.ToString();
ShopOwnedItems[3].text = SaveManager.revive.ToString();
int[] unlockedSkins = new int[] { SaveManager.skin2Unlocked, SaveManager.skin3Unlocked, SaveManager.skin4Unlocked };
for (int i = 0; i < 4; i++)
{
//If this is the current skin
if (SaveManager.currentSkinID == i)
{
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[0];
}
else
{
if (unlockedSkins[i])
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[1];
else
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[2];
}
}
}
I'm trying to swap sprites if any of the skins are unlocked in the UpdateShopDisplay() function using a counter this is the function in javascript that works fine but i need to convert to c# and having some trouble
private function UpdateShopDisplay() { //Update texts coinAmmount.text = Save$$anonymous$$anagerJS.coinAmmount.ToString();
ShopOwnedItems[0].text = Save$$anonymous$$anagerJS.extraSpeed.ToString();
ShopOwnedItems[1].text = Save$$anonymous$$anagerJS.shield.ToString();
ShopOwnedItems[2].text = Save$$anonymous$$anagerJS.sonicWave.ToString();
ShopOwnedItems[3].text = Save$$anonymous$$anagerJS.revive.ToString();
var unlockedSkins = [true, Save$$anonymous$$anagerJS.skin2Unlocked == 1, Save$$anonymous$$anagerJS.skin3Unlocked == 1, Save$$anonymous$$anagerJS.skin4Unlocked == 1];
for (var i : int = 0; i < 4; i++) { //If this is the current skin if (Save$$anonymous$$anagerJS.currentSkinID == i) { shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[0]; } else { if (unlockedSkins[i]) shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[1]; else shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[2]; } }}
var unlockedSkins = [true, Save$$anonymous$$anagerJS.skin2Unlocked == 1, Save$$anonymous$$anagerJS.skin3Unlocked == 1, Save$$anonymous$$anagerJS.skin4Unlocked == 1]
Are the skinxUnlocked variables bools? you will need to change ==1 to ==true if this is the case.
Answer by barbe63 · Jul 01, 2015 at 09:30 AM
Change this :
int[] unlockedSkins = new int[] { SaveManager.skin2Unlocked, SaveManager.skin3Unlocked, SaveManager.skin4Unlocked };
to this
bool[] unlockedSkins = new bool[] {true, SaveManager.skin2Unlocked, SaveManager.skin3Unlocked, SaveManager.skin4Unlocked };
//you need 4 terms for your loop and if I understood it well you need the first term to be true
Also SaveManager.skin2Unlocked and others like this need to be bool as well. Otherwise you'll need to convert them as bool with a ternary operator in your function call.
thank you @barbe63 i got the function working it now looks like this
private void UpdateShopDisplay() { //Update texts coinAmmount.text = Save$$anonymous$$anager.coinAmmount.ToString();
ShopOwnedItems[0].text = Save$$anonymous$$anager.extraSpeed.ToString();
ShopOwnedItems[1].text = Save$$anonymous$$anager.shield.ToString();
ShopOwnedItems[2].text = Save$$anonymous$$anager.sonicWave.ToString();
ShopOwnedItems[3].text = Save$$anonymous$$anager.revive.ToString();
bool[] unlockedSkins = new bool[] { true, Save$$anonymous$$anager.skin2Unlocked == 1, Save$$anonymous$$anager.skin3Unlocked == 1, Save$$anonymous$$anager.skin4Unlocked == 1 };
for (int i = 0; i < 4; i++)
{
//If this is the current skin
if (Save$$anonymous$$anager.currentSkinID == i)
{
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[0];
}
else
{
if (unlockedSkins[i])
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[1];
else
shopSubmarineButtons[i].sprite = ShopSkinButtonSprites[2];
}
}
}
appreciate the help everyone!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[c#} Combining if statements 1 Answer
Layermask for OnTriggerStay 2 Answers
convert c# to JavaScript Problem 0 Answers