Jump to content

"No viable alternative at input 'if'"


niallmcfc

Recommended Posts

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

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

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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...