Can a script change another script's propertiesvariables?

Post » Tue Jun 19, 2012 12:11 pm

So the idea was to add a script to a weapon and make it so that when the actor is hit (the "OnHit" event would be used) a message would be shown.

However the problem is that OnHit does not work with weapons unfortunately, so the OnHit script would have to be attached to the player character instead and not the weapon itself.

So what we want to do here is make it so that when the player is hit a variable/property in the weapon script is changed but only because another script attached to the PC says to do so (only when hit). I also know that when the PC is hit by a specific weapon the OnHit event can be called on that basis alone but this script is for a weapon that the PC is wielding and not any enemy.

:ermm:
User avatar
Harry Hearing
 
Posts: 3366
Joined: Sun Jul 22, 2007 6:19 am

Post » Mon Jun 18, 2012 11:05 pm

If I understand correctly, you want to make a quest with a Player alias. Attach the script to the player alias

OnHit does not attach to weapons. It attaches to the actor - It fires when the actor is hit. Look at the OnHit function, you'll see akSource. This is the weapon that you wanted to attach the script to.

So, you just need a simple check to see if the weapon you want has hit the actor, if true then you send your message, and access (increment?) the external variable you want.

Alternatively, you could just use local variables in this script - but I'm not sure what exactly you're trying to accomplish.
User avatar
koumba
 
Posts: 3394
Joined: Thu Mar 22, 2007 8:39 pm

Post » Tue Jun 19, 2012 3:05 am

Variables are private, but properties can be accessed externally. You can access the properties on an object in the same way as you can access the functions on an object - just make sure you cast it to the correct type so the compiler will recognise the properties. You can read about that in one of my tutorials - http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx

Cipscis
User avatar
Steeeph
 
Posts: 3443
Joined: Wed Apr 04, 2007 8:28 am

Post » Tue Jun 19, 2012 12:35 am

If I understand correctly, you want to make a quest with a Player alias. Attach the script to the player alias

OnHit does not attach to weapons. It attaches to the actor - It fires when the actor is hit. Look at the OnHit function, you'll see akSource. This is the weapon that you wanted to attach the script to.

So, you just need a simple check to see if the weapon you want has hit the actor, if true then you send your message, and access (increment?) the external variable you want.

Alternatively, you could just use local variables in this script - but I'm not sure what exactly you're trying to accomplish.

No its a weapon your character is holding not one being wielded by the enemy.
User avatar
carla
 
Posts: 3345
Joined: Wed Aug 23, 2006 8:36 am

Post » Tue Jun 19, 2012 6:38 am

Variables are private, but properties can be accessed externally. You can access the properties on an object in the same way as you can access the functions on an object - just make sure you cast it to the correct type so the compiler will recognise the properties. You can read about that in one of my tutorials - http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx

Cipscis

Cheers, I will look into this :D.

/gives medal
User avatar
Courtney Foren
 
Posts: 3418
Joined: Sun Mar 11, 2007 6:49 am

Post » Tue Jun 19, 2012 2:23 pm

Besides what Cispis says, If you want to change the variables of a script from another one, make a function to change those variables in it's own script and call that function from the other script.
User avatar
Lory Da Costa
 
Posts: 3463
Joined: Fri Dec 15, 2006 12:30 pm

Post » Tue Jun 19, 2012 7:18 am

Besides what Cispis says, If you want to change the variables of a script from another one, make a function to change those variables in it's own script and call that function from the other script.

Give an example?
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Tue Jun 19, 2012 12:07 am

In the script with the variable you want to change:
int intVar = 0Function SetIntVar(int value)	intVar = valueEndFunctionint Function GetIntVar()	return intVarEndFunction

In the script that sets/gets the function:
OtherScriptName Property ObjectWithIntVar autoint OtherIntVar = 0; Later, inside some function:OtherIntVar = OtherScriptName.GetIntVar()OtherScriptName.SetIntVar(3)

Cipscis
User avatar
Campbell
 
Posts: 3262
Joined: Tue Jun 05, 2007 8:54 am

Post » Tue Jun 19, 2012 8:36 am

So the idea was to add a script to a weapon and make it so that when the actor is hit (the "OnHit" event would be used) a message would be shown.

However the problem is that OnHit does not work with weapons unfortunately, so the OnHit script would have to be attached to the player character instead and not the weapon itself.


I was thinking, if you wish to have 'OnHit' event applied to weapon, the best way would be to create an enchantment, add the script to that enchantment's Magic Effect. Then you can alter other scripts Properties via that Enchantment script
User avatar
Andrew
 
Posts: 3521
Joined: Tue May 08, 2007 1:44 am

Post » Tue Jun 19, 2012 8:28 am

In the script with the variable you want to change:
int intVar = 0 Function SetIntVar(int value) intVar = value EndFunction int Function GetIntVar() return intVar EndFunction 
In the script that sets/gets the function:
OtherScriptName Property ObjectWithIntVar auto int OtherIntVar = 0 ; Later, inside some function: OtherIntVar = OtherScriptName.GetIntVar() OtherScriptName.SetIntVar(3)
Cipscis

Does not seem to want to work within the OnHit event.

:confused:
User avatar
CRuzIta LUVz grlz
 
Posts: 3388
Joined: Fri Aug 24, 2007 11:44 am

Post » Tue Jun 19, 2012 1:01 am

I was thinking, if you wish to have 'OnHit' event applied to weapon, the best way would be to create an enchantment, add the script to that enchantment's Magic Effect. Then you can alter other scripts Properties via that Enchantment script

Verification: Does that mean when your character hits a target and not when a enemy hits your character?
User avatar
Natasha Biss
 
Posts: 3491
Joined: Mon Jul 10, 2006 8:47 am

Post » Tue Jun 19, 2012 1:50 pm

Verification: Does that mean when your character hits a target and not when a enemy hits your character?

Actually, it works both ways. BUT, you can filter that effect to apply only on whatever player is hitting via simple if/endif checks
User avatar
Kitana Lucas
 
Posts: 3421
Joined: Sat Aug 12, 2006 1:24 pm

Post » Tue Jun 19, 2012 2:21 am

Actually, it works both ways. BUT, you can filter that effect to apply only on whatever player is hitting via simple if/endif checks

Lol you've just given me a alternate method on how to go about my idea which should work far better but it will take a script rewrite...

:blink:
User avatar
Chavala
 
Posts: 3355
Joined: Sun Jun 25, 2006 5:28 am

Post » Tue Jun 19, 2012 7:04 am

Good luck w/ your mod :)
Let us know if it works
User avatar
danni Marchant
 
Posts: 3420
Joined: Sat Oct 07, 2006 2:32 am


Return to V - Skyrim