dvkkha Posted November 5, 2016 Share Posted November 5, 2016 I need your help. I'm working on a script, the following is just the essence of the problem: container property HBRibCage auto container property HCRibCage auto container property HCRibCage auto actor Victim race VictimRace Event OnEffectStart(Actor Target, Actor Caster) victim = target trace("victim == " + victim + ", is this right?") EndEvent ; When Victim dies.... Event OnDying(Actor Killer) ;Get Race ActorBase VictimBase = Victim.GetBaseObject() as ActorBase VictimRace = VictimBase.GetRace() ;----------------Set Race specific Variables---------------------------------- ;---Is Victim Human? if ListHumanB.HasForm(VictimRace) objectreference ObjContainer = Victim.AttachAshPile(HBRibCage) elseif ListHumanC.HasForm(VictimRace) objectreference ObjContainer = Victim.AttachAshPile(HCRibCage) else objectreference ObjContainer = Victim.AttachAshPile(HDRibCage) endif ;Change Container Owner to Player ObjContainer.SetActorOwner(Game.GetPlayer().GetActorBase()) The compiler throws an exception "variable ObjContainer is undefined". I'm pretty sure the reason for this is that I call the objectreference in if statements and the compiler does not know if it ever gets defined at all. Problem is, I need a solution for this because I want the AshPile Container to be different depending on race. I don't know how to put the container property in a variable to call Victim.AttachAshPile(variable) so I can call the objectreference outsite of the if statements. Does someone have a solution for me? Link to comment Share on other sites More sharing options...
FrankFamily Posted November 5, 2016 Share Posted November 5, 2016 First of all you have 2 HCRibcage and no HDRibCage The reason the compiler sais that is because you are defining it within the if statements and then using it outside, that has a technical name, scope block or something like that, i'm no programmer but, long story short, you can't do that. Define it outside and change its value within the if statements instead, as in: objectreference ObjContainer if ListHumanB.HasForm(VictimRace) ObjContainer = Victim.AttachAshPile(HBRibCage) elseif ListHumanC.HasForm(VictimRace) ObjContainer = Victim.AttachAshPile(HCRibCage) else ObjContainer = Victim.AttachAshPile(HDRibCage) endif ObjContainer.SetActorOwner(Game.GetPlayer().GetActorBase())A variable defined within an if statement can only be used within that statement just like variables within a function are only available to it. Link to comment Share on other sites More sharing options...
dvkkha Posted November 5, 2016 Author Share Posted November 5, 2016 Yes, I copied the wrong parts out of my script, therefore HDRibCage gets used. Man, that was exactly my problem and your solution is as simple as it could be. I did not know what I can just use objectreference like that.My script compiled succesfully, thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts