Comparing Self?

Post » Wed Jun 20, 2012 4:30 am

Hi.

I want to compare self to a property array, but I'm getting compilation errors.
Here's my code:

MiscObject[] Property HT_TrapItem  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)int i = 0   while i < 5	  if (Self == HT_TrapItem[i])	  endif	  i += 1   endwhileendevent

EDIT: I know that there's a Self in this event, so that's not the problem. I am pretty sure that it's the way I wrote it that is wrong.
User avatar
Unstoppable Judge
 
Posts: 3337
Joined: Sat Jul 29, 2006 11:22 pm

Post » Wed Jun 20, 2012 5:21 am

I don't know why your script doesn't compile but it can be condensed like this :

MiscObject[] Property HT_TrapItem  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)endevent

Problem solved... Please read this : http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/
User avatar
Samantha Wood
 
Posts: 3286
Joined: Sun Oct 15, 2006 5:03 am

Post » Wed Jun 20, 2012 12:15 am

I don't know why your script doesn't compile but it can be condensed like this :

MiscObject[] Property HT_TrapItem  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)endevent

Problem solved... Please read this : http://www.gamesas.com/topic/1347469-how-to-ask-for-scripting-help/

How does any of that help?
Problem not solved.
User avatar
Bellismydesi
 
Posts: 3360
Joined: Sun Jun 18, 2006 7:25 am

Post » Wed Jun 20, 2012 1:01 am

You'll need to Cast the value of that Array Element as whatever "self" is.
In your e.g., can I assume that "self" will be a MiscObject?
If so, this could probably work:
Note the "as MiscObject" after the Array Element.
Spoiler
MiscObject[] Property HT_TrapItem  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)int i = 0   while i < 5		  if (Self == HT_TrapItem[i] as MiscObject)		  endif		  i += 1   endwhileendevent

If that doesn't work, what Compiler Error do you get?
User avatar
carley moss
 
Posts: 3331
Joined: Tue Jun 20, 2006 5:05 pm

Post » Wed Jun 20, 2012 4:25 am

Error message: "cannot cast a ht_playerdroptrap to a miscobject, types are incompatible"

It seems that "Self" in this case is the script itself.
Which is strange, because later in the script I use "Self.PlaceAtMe()" and "Delete()" which works. (Meaning the item is deleted and there's a new item in it's place.)

-If "Self" points at the script, how can I get the item that the script is attached to?


EDIT:
Scriptname HT_PlayerDropTrap extends ObjectReference


EDIT #2: Using "as MiscObject" didn't work either.
User avatar
celebrity
 
Posts: 3522
Joined: Mon Jul 02, 2007 12:53 pm

Post » Tue Jun 19, 2012 11:29 pm

Ok...I get it now.
Cast it as "ht_playerdroptrap" like this:
if (Self == HT_TrapItem[i] as ht_playerdroptrap)
When you create a new Script it becomes a new Class which extends one of the native forms (e.g. MiscObject).
So those items you are attaching the Script to becomes that new class.
In this case, the new Class is "ht_playerdroptrap".
Try that, please.
Let me know how you go.
User avatar
SexyPimpAss
 
Posts: 3416
Joined: Wed Nov 15, 2006 9:24 am

Post » Wed Jun 20, 2012 2:42 am

Try that, please.
Let me know how you go.

I would, but I got excited and did something rash. I do that a lot.. I removed all the global/array variables, properties and whatnot. (They were just temporary anyway, and I used them to test an idea I had.)

I got excited because I realized that "Self" points at the script. So I guessed that "Delete()" = "Self.Delete()" meaning the script would get destroyed and only run once.
I figured that there has to be a way to point at the "ObjectReference" (or whatever it's called), instead of pointing at the script. -That way I could keep the script and destroy the actual item.

Anyway, here's the script that I'm trying to get to work:
Scriptname HT_PlayerDropTrap extends ObjectReference  {A script that will replace the dummy item with an actual trap when the player drops it.}Activator Property HT_TrapActivator  Autoevent OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)   if (akOldContainer && !akNewContainer)	  Self.PlaceAtMe(HT_TrapActivator)	  Delete()   endifendevent

What it does is: when I drop the dummy item that the script is attached to it removes the items and replaces it with an activator.

What's wrong with it: It only does this once. If I drop several items only the first once is turned into an activator, the rest are dropped as dummy items.
-I figured that if I "Delete()" the actual MiscObject, instead of the script it might work the way I want it to?

EDIT: For example:
MiscObject HT_Whatername Auto;event   ;Other actions..   HT_Whatevername.Delete();endevent
User avatar
Hope Greenhaw
 
Posts: 3368
Joined: Fri Aug 17, 2007 8:44 pm


Return to V - Skyrim