Jump to content

Syntax for Object Reference


VinceBly

Recommended Posts

I wish to use an activator to control another object . For example, when a pressure plate is activated, a spike withdraws into the floor. Unfortunately. I am missing some subtlety about object references, or maybe something not so subtle.

 

As a simple example, I want the activator to enable or disable MyLight1, where MyLight1 is a unique name and is in the same cell as the activator. I have also marked MyLight1 as a persistent reference. I've tried an OnActivate script using "MyLight1.enable" or "MyLight1Ref.enable", but these were rejected by the script editor. I was able to compile and execute the following script:

 

Scriptname TestScript1

 

Short flag

Ref rvar1

 

Begin OnActivate

Set rvar1 to MyLight1

If flag == 0

rvar1.disable

set flag to 1

Else

rvar1.enable

set flag to 0

EndIf
End

 

The good news is the script editor accepts this. The bad news is what is does is disable the activator--not what I had in mind at all. If you answer this, please assume I know nearly nothing (you won't be far off). BTW, is there someway to indent without the extra carrage returns?

 

Thanks,

 

- Vince Bly -

Link to comment
Share on other sites

How about this?

Scriptname TestScript1

Begin OnActivate
if mylightref.getdisabled == 1
mylightref.enable
endif
if mylightref.getdisabled == 0
mylightref.disable
endif
End

 

Mylightref here is the reference ID of course.

I don't know why the script editor didn't accept it. There's probably a small mistake somewhere. If this doesn't work the way you want it to, maybe you can post the original script that it didn't accept?

Link to comment
Share on other sites

You tried quoting it?

This is strange...

 

I usually do like this

Scriptname TestScript1

 

Short flag

Ref rvar ; numbers in variables are bad. No-go for real programmers.

 

Begin OnActivate

 

Set rvar1 to "MyLight" ; still no numbers. Hate them.

If flag < 1 ; shortens the script by ONE byte :)

rvar.disable

set flag to 1

 

Else

rvar.enable

set flag to 0

EndIf

End

 

Worked in the CS for me.

Link to comment
Share on other sites

How about this?

Scriptname TestScript1

Begin OnActivate
if mylightref.getdisabled == 1
mylightref.enable
endif
if mylightref.getdisabled == 0
mylightref.disable
endif
End

 

Mylightref here is the reference ID of course.

I don't know why the script editor didn't accept it. There's probably a small mistake somewhere. If this doesn't work the way you want it to, maybe you can post the original script that it didn't accept?

 

Povuholo,

 

You were wrong! I didn't make "a small mistake somewhere". I made a really big mistake! All kidding aside, you have given me very useful information that will make my future CS work easier, and I thank you for it. Now that I understand my mistake, I will try to explain it clearly so others that are learning, as I am, may not make the same mistake. Please feel free to expand or correct what I say.

 

My fundamental mistake was confusing the editor ID with the reference ID. When I take some item from the CS Object Window item list and edit it, changing its name, and answering the "Create new Form?" question with "Yes", I create a new item that shows up in the CS's Object Window under the appropriate category. I can drag a copy of this item into the Render Window. When I do this, I am creating a particular instance of that new item. If I went back to the Object Window and dragged another copy of the item somewhere else in the Render Window, I have created a second instance of the item. When one writes a script line like objectreference.somefunction, the intention is to apply somefunction to a particular instance of the item, not all instances of it. So, all instances of the item will have the same editor ID, but each instance needs its own reference ID, if you plan to reference it later. It seems good practice to apply a reference ID to every instance of any unique item you use in a mod.

 

Again, my error was using the editor ID as an object reference, instead of the reference ID for the particular instance I wanted to affect.

 

- Vince Bly -

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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