Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

javascript NullReferenceException: Object reference not set to an instance of an object

$
0
0
Hi everyone. Well, i'm trying to make an Armor system for my RPG like game. But i'm having trouble setting the starter armor value to the character when it is first instantiated. First, i have a script with a class called Armor. Like this: ArmorScript.js #pragma strict import System.Collections.Generic; class Armor{ var listValuesBonus: List.; } The listValuesBonus will receive the values of defense, number of slots (0 to 2), and the bonuses of these slots. Also, in the character script i have this: CharacterScript.js #pragma strict import System.Collections.Generic; var classe: PersonagemCombatenteClasse; var status : PersonagemCombatenteStatus; var armor : List.; var armorInitial: Armor; function Awake() { classe = StatusPersonagens.GetClasseCombatente(); status = StatusPersonagens.GetCombatenteStatusBasico(classe); armor = new List.(); armorInitial = new Armor(); if (armorInitial == null){ //Tried this to figure out if armorInitial was null Debug.Log("armorInitial == null"); //but it's not } else if (armorInitial.listValuesBonus == null){ Debug.Log("listValuesBonus == null"); armorInitial.listValuesBonus.Add(1); armorInitial.listValuesBonus.Add(0); SetListArmorBonus(armorInitial); } } function SetListArmorBonus (newArmor: Armor){ armor.Add(newArmor); } But when the character is instantiated and try to Add() the values to listValuesBonus i receive this message error: NullReferenceException: Object reference not set to an instance of an object Combatente.Awake () (at Assets/Scripts/Combatente.js:22) Can someone help, please? Thank for the attention and sorry for any english errors.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>