Simple script help please

Post » Tue Jun 19, 2012 11:48 pm

Hi to all script masters! Simple question ... how do I set a variable to an actor value amount? I can't really work out where to put the line

Scriptname fistyswordy extends Actor{adds and removes unarmed damage from associated weapon}int iUnarmed;a variable that I intend to hold current unarmed damage avEvent OnEquipped(Actor akActor)	if (akActor == Game.GetPlayer())	  Game.GetPlayer().ModActorValue("meleedamage", iUnarmed)	   ;or setav or forceav?  endIfendEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()	  Game.GetPlayer().ModActorValue("meleedamage", -iUnarmed)  endIfendEvent

So that seems ok, but I need to set the variable iUnarmed

something like this?
int iUnarmed = Game.GetPlayer().GetActorValue("unarmeddamage") as int

but where does it go?

Thanks in advance for any help. Trying to get my head around a million new things at once here.
User avatar
Janette Segura
 
Posts: 3512
Joined: Wed Aug 22, 2007 12:36 am

Post » Wed Jun 20, 2012 12:05 am

Replace your 'int iUnarmed' line with this:
int iUnarmed = Game.GetPlayer().GetActorValue("UnarmedDamage") as int
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Wed Jun 20, 2012 7:21 am

that is how I initially tried it, it wont compile

specifically it says the errors are that line (4) -

no viable alternative as input 'Game'
required (...)+ loop did not match anything as input '.'
unknown user flag Game

I tried (badly) to define it as a function also, but didnt get anywhere
User avatar
Ash
 
Posts: 3392
Joined: Tue Jun 13, 2006 8:59 am

Post » Wed Jun 20, 2012 6:32 am

DO You have iUnarmed=0?
User avatar
James Potter
 
Posts: 3418
Joined: Sat Jul 07, 2007 11:40 am

Post » Wed Jun 20, 2012 7:33 am

I have compiled in my the CK and i haven't any mistakes
User avatar
Rudi Carter
 
Posts: 3365
Joined: Fri Sep 01, 2006 11:09 pm

Post » Wed Jun 20, 2012 7:45 am

float  iUnarmed;a variable that I intend to hold current unarmed damage avEvent OnEquipped(Actor akActor)IUnarmed=Game.GetPlayer().GetActorValue("UnarmedDamage")	    if (akActor == Game.GetPlayer())		  Game.GetPlayer().ModActorValue("meleedamage", iUnarmed)		   ;or setav or forceav?  endIfendEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()		  Game.GetPlayer().ModActorValue("meleedamage", -iUnarmed)  endIfendEvent
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Wed Jun 20, 2012 3:52 am

ha, so it just had to be defined in the event?

do I need a similar line in the second event, or will it keep track of the variable throughout the script?

Edit:
So "meleedamage" does nothing? Urggh. Seems to return 0 no matter what I do. Any thoughts for a work around? Trying to add unarmed damage to a weapon on the fly
User avatar
Conor Byrne
 
Posts: 3411
Joined: Wed Jul 11, 2007 3:37 pm

Post » Wed Jun 20, 2012 2:57 am

Neither variables declared outside of function bodies nor properties can be initialised to non-literal values. If you want to use a non-literal value, then you have to either assign it after the declaration, or declare and initialise a variable within a function body. If the declaration occurs outside of a function body, then you can only initialise to a http://www.creationkit.com/Literals_Reference.

Cipscis
User avatar
Adam Baumgartner
 
Posts: 3344
Joined: Wed May 30, 2007 12:12 pm

Post » Wed Jun 20, 2012 5:37 am

Yeah, I thought that might be the case, but I really couldn't get my head around how to use functions. The wiki only has functions on their own, not called in other scripts. Your tutorials made more sense, but still having trouble

does this work?
Spoiler

Scriptname potpFistDamage extends Actor{adds and removes unarmed damage from associated weapon}Float fUnarmed;a variable that I intend to hold current unarmed damage avFunction GetUnarmed()	  Game.GetPlayer().GetActorValue("UnarmedDamage")EndFunctionEvent OnEquipped(Actor akActor)   fUnarmed = GetUnarmed()	  if (akActor == Game.GetPlayer())	  Game.GetPlayer().ModActorValue("meleedamage", fUnarmed) ;or setav or forceav?	  endIfendEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()	  Game.GetPlayer().ModActorValue("meleedamage", -fUnarmed)  endIfendEvent

The wiki also implies I can just do something like
int iUnarmed Game.GetPlayer().GetActorValue("UnarmedDamage") as int
but I don't think that worked when I tried

edit: at the end of the day this is all a bit academic, because meleedamage appears to be unused, and doesn't do what I need it to. I think I have a dirty workaround, without scripting. This discussion is helping me with scripting though, so thanks for any replies, and for replies thus far!
User avatar
Amiee Kent
 
Posts: 3447
Joined: Thu Jun 15, 2006 2:25 pm

Post » Tue Jun 19, 2012 7:45 pm

Remember events are functions too, so although that would work you don't need to use a custom function like your "GetUnarmed" function.

The initialisation line that you posted can compile, but only if it's inside the body of a function (including events). However, declaring a variable inside a function also means that variable will cease to exist when the function is complete, so it's not always appropriate.

Cipscis
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am

Post » Wed Jun 20, 2012 12:48 am

cheers cipscis/cloud

that helps a lot

ps. in the case where I use that initialisation inside the first event, it would not be accessible by the second event right? So I would have to do it again, or use the seperate function I posted right?
User avatar
Cheryl Rice
 
Posts: 3412
Joined: Sat Aug 11, 2007 7:44 am

Post » Tue Jun 19, 2012 4:54 pm

Function GetUnarmed()	  Game.GetPlayer().GetActorValue("UnarmedDamage")EndFunction

You didn't give the function a return type, and you didn't return anything

Float Function GetUnarmed()	  return Game.GetPlayer().GetActorValue("UnarmedDamage")EndFunction

Also you don't need a function at all here, you could go
Spoiler

Scriptname potpFistDamage extends Actor{adds and removes unarmed damage from associated weapon}Float fUnarmed;a variable that I intend to hold current unarmed damage avEvent OnEquipped(Actor akActor)	fUnarmed = Game.GetPlayer().GetActorValue("UnarmedDamage")	If (akActor == Game.GetPlayer())		Game.GetPlayer().ModActorValue("meleedamage", fUnarmed) ;or setav or forceav?	EndIfEndEventEvent OnUnequipped(Actor akActor)	If akActor == Game.GetPlayer()		Game.GetPlayer().ModActorValue("meleedamage", -fUnarmed)	EndIfEndEvent
User avatar
Matt Terry
 
Posts: 3453
Joined: Sun May 13, 2007 10:58 am

Post » Tue Jun 19, 2012 5:42 pm

ps. in the case where I use that initialisation inside the first event, it would not be accessible by the second event right? So I would have to do it again, or use the seperate function I posted right?
No, as long as you keep fUnarmed declared outside of the event, it can be accessed in both events

Example 1
Float fUnarmedEvent OnEquipped(Actor akActor)	fUnarmed = 10.5EndEvent
fUnarmed can be accessed in any function/event in this script

Example 2
Event OnEquipped(Actor akActor)	Float fUnarmed = 10.5EndEvent
Or
Event OnEquipped(Actor akActor)	Float fUnarmed	fUnarmed = 10.5EndEvent
fUnarmed can only be accessed in the OnEquipped event
User avatar
Charlie Sarson
 
Posts: 3445
Joined: Thu May 17, 2007 12:38 pm

Post » Wed Jun 20, 2012 5:51 am

cheers xtynct

sorry, but I cant get that script to compile either

seperately, in your examples, in example 1, any function can access fUnarmed, but it will restore default (0) in any subsequent functions right? The 10.5 value won't be stored?
User avatar
Joanne
 
Posts: 3357
Joined: Fri Oct 27, 2006 1:25 pm

Post » Tue Jun 19, 2012 5:02 pm

What was the compile error?

In example 1 any function/event can access fUnarmed and its value will be whatever it was last set to, it will be 10.5 to any function/event that checks until it is changed.
User avatar
Kayleigh Mcneil
 
Posts: 3352
Joined: Thu Jun 29, 2006 7:32 am

Post » Tue Jun 19, 2012 3:46 pm

Quick tutorial on variable scope
Spoiler

ScriptName Example1 extends Int exampleIntEvent OnEquipped(Actor akActor)EndEventEvent OnUnequipped(Actor akActor)EndEvent
In this script exampleInt's scope is the entire script, any function/event can look at exampleInt, any function/event that changes exampleInt will change it for every other function/event


ScriptName Example2 extends Event OnEquipped(Actor akActor)	Int exampleInt	EndEventEvent OnUnequipped(Actor akActor)EndEvent
In this script exampleInt's scope is the OnEquipped event, only OnEquipped knows exampleInt exists, if OnEquipped changes exampleInt's value it will only be changed for OnEquipped
Also once OnEquipped finishes exampleInt dies (If OnEquipped runs again exampleInt's value will be reset)


ScriptName Example3 extends Event OnEquipped(Actor akActor)	Int exampleInt	EndEventEvent OnUnequipped(Actor akActor)	Int exampleIntEndEvent
In this script their are 2 different exampleInt's. The one in the OnEquipped event is not the same as the one in the OnUnequipped event.
User avatar
kirsty williams
 
Posts: 3509
Joined: Sun Oct 08, 2006 5:56 am

Post » Wed Jun 20, 2012 4:01 am

hmm ... just tried again and it compiled

thanks for the clear tute
User avatar
Soph
 
Posts: 3499
Joined: Fri Oct 13, 2006 8:24 am


Return to V - Skyrim