niallmcfc Posted February 17, 2012 Share Posted February 17, 2012 I've made a very simple script, that should check if the player has an apple (FoodApple), and if they do, replace it with an apple that can be used in alchemy (IngrApple01). However, whenever I try to save, I get possibly this suitably annoying error: "no viable alternative at input 'if'". This is my script, does anybody know why it's rejecting it? Forgive me if it's blindingly obvious, I'm finding Papyrus very hard to adapt to. Scriptname AppleReplacer extends ObjectReference {Replace apple (food) with apple (ingredient)} Food Property FoodApple auto Ingredient Property IngrApple01 auto int Function GetItemCount(Form FoodApple) native if(Game.GetPlayer().GetItemCount(FoodApple)==0) Game.GetPlayer().RemoveItem(FoodApple) Game.GetPlayer().AddItem(IngrApple01) endif Link to comment Share on other sites More sharing options...
Infininja Posted February 18, 2012 Share Posted February 18, 2012 I'm a novice myself, but I found if statements need to be within events or functions, for example. Scriptname HelloWorldScript extends ObjectReference {This is my very first script!} int count ;stores the number of times this object has been activated Event OnActivate(ObjectReference akActionRef) count = count + 1 if count == 1 Debug.MessageBox("Hello, World!") elseif count == 2 Debug.MessageBox("Hello, World. Again!") else Debug.MessageBox("Hello, World. Enough already!") endif endEvent From the Creation Kit tutorial. Their if statement is between Event OnActivate and endEvent. Link to comment Share on other sites More sharing options...
cscottydont Posted February 18, 2012 Share Posted February 18, 2012 I'm a novice myself, but I found if statements need to be within events or functions, for example. Infininja is correct. What is this script going to be attached to? Link to comment Share on other sites More sharing options...
niallmcfc Posted February 18, 2012 Author Share Posted February 18, 2012 Yeah, he was right. It works now. I was going to attach it to the FoodApple item, but food can't have papyrus on it. So I'm going to make a alteration spell (like transmute) to do it instead. It's a bit embarrassing, really, considering almost every other language on the planet needs events as well... Link to comment Share on other sites More sharing options...
Mansh00ter Posted February 18, 2012 Share Posted February 18, 2012 Of course food can have papyrus on it, it just needs to be attached via a script type magic effect. Use onEffectStart() event - onActivate won't work. Link to comment Share on other sites More sharing options...
niallmcfc Posted February 18, 2012 Author Share Posted February 18, 2012 When I click the ... next to the scripts button, nothing happens. Link to comment Share on other sites More sharing options...
Mansh00ter Posted February 19, 2012 Share Posted February 19, 2012 The food scripts button does not do anything, it's not used. Instead, create a new Magic Effect, set it's type to "script" and then attach your papyrus script to that. Then you can attach the Magic Effect to your food item so that it fires when the player consumes the food. Link to comment Share on other sites More sharing options...
Mansh00ter Posted February 19, 2012 Share Posted February 19, 2012 Oh, and just in case, when creating the Magic Effect of the kind you describe I always attach a condition that the Subject GetIsID is "Actor: Player" or the script won't fire. You don't want NPCs eating food to accidentally trigger scripts. Not positive NPCs can actually consume food, but I like to be sure there are no unpredictable script firings. Link to comment Share on other sites More sharing options...
niallmcfc Posted February 19, 2012 Author Share Posted February 19, 2012 That's a interesting work around... For what I plan to do, though, I don't want the player eating the food. Let me explain. My plan is to make food usable in alchemy. I can't just remove the food, though, as people with the food will then lose it upon loading the mod. So, to combat this, my idea was to run a script that actively replaces the food with another item (the same, but can be used in alchemy), upon detecting that there is some of that food in the player's inventory. That way, none of the food will be lost. That's why the fact that there's no working script button is a problem- although I guess I could use your method, and change it so that the food has no properties until eaten. So that's why I'm now resorting to a 'transmute' spell instead. To me, it seems the best option given the circumstances. Link to comment Share on other sites More sharing options...
cscottydont Posted February 19, 2012 Share Posted February 19, 2012 A transmute spell sounds like a good idea to me. You could also make yourself an activator type object and attach a script to that. It would be much less portable but would require less from the player (just a click, compared to equipping/casting a spell) Link to comment Share on other sites More sharing options...
Recommended Posts