- Home /
Question by
DarthPork · Jan 19, 2015 at 07:45 AM ·
javascriptvariablegetcomponentaccessing from any script
Issues accessing a variable in another script
Quick Breakdown
armorStats.js:
// I just need to get this int into another script is the issue.
var toAquire: int;
combatcontroller.js:
// I grab the armorStats script at somepoint into this script/controler, if the component name is armorstats or weaponsstats, etc.. i set activeCardStast to it like so
var activeCardStats;
var activeCard : GameObject;
if (activeCardObject.GetComponent(monsterStats) != null){ //look for the different Stat scripts (by name / if it exists)
activeCardStats = activeCardObject.GetComponent(monsterStats);
}
if (activeCardObject.GetComponent(armorStats) != null){
activeCardStats = activeCardObject.GetComponent(armorStats);
}
And finally at some point I want to display a Button on the ui if certain conditions are met (position of card on board mainly) that OnClick() has the following:
var warrior : GameObject;
var rogue : GameObject;
var wizard : GameObject;
var cleric : GameObject;
var activeCard : GameObject;
var aquireNumber : int;
var combatController : GameObject;
function Start () {
warrior = GameObject.Find("Warrior");
rogue = GameObject.Find("Rogue");
wizard = GameObject.Find("Wizard");
cleric = GameObject.Find("Cleric");
activeCard = GameObject.Find("Active Encounter");
combatController = GameObject.Find("_CombatManager");
}
function RollToGetCard(){
activeCard = GameObject.Find("Active Encounter");
combatController = GameObject.Find("_CombatManager");
var activeCardStats = combatController.GetComponent(CombatController).activeCardStats;
// I'm either missing functionality or correct syntax here to get toAquire from armorstats.js
At this point, I see the armorstats: print ("Roll button clicked, card stats script found: " + activeCardStats); ^this displays "Roll button clicked, card stats script fround" (armorStats)
But I cannot actually get the toAquire in my original script to save my life..I just want to override a similar variable in this script with that one. (I'm going to sleep on it, but any help would be appreciated)
Comment