Aller au contenu

Photo

GetLocalObject problem...


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
MammonTheViscount

MammonTheViscount
  • Members
  • 35 messages
http://pastebin.com/ehw3WMdn

void main()
{
    object oPC = GetLastUsedBy();  //get pc's name for the message
    object oAlarm1 = OBJECT_SELF;    //object the script is on, first alarm device
    object oAlarm2 = GetLocalObject(oAlarm1,"LINKED_OBJECT").     //get object oAlarm2, stored as a  variable on the object the script is on
    string sMessage = "You have activated the alarm!";  //the message to be sent to the pc activating the gong
    SendMessageToPC(oPC, sMessage); //sends the message off
    ExecuteScript("alarmgoesoff",oAlarm2);     //execute the scripts on the objects
    ExecuteScript("alarmgoesoff",oAlarm1);
    }

Everything in the script works except for the Get LocalObject line (because if i just plug in the variable name, the script fires as it's supposed to).  As is, oAlarm1 activates, but oAlarm2 does not.

Would appreciate the help.

Modifié par MammonTheViscount, 26 juillet 2010 - 08:10 .


#2
MammonTheViscount

MammonTheViscount
  • Members
  • 35 messages
void main()
{
	object oPC = GetLastUsedBy();
	object oAlarm1 = OBJECT_SELF;
	string sAlarm2 = GetLocalString(oAlarm1,"LINKED_OBJECT");
	object oAlarm2 = GetObjectByTag(sAlarm2);
	string sMessage = "You have activated the alarm!";
	SendMessageToPC(oPC, sMessage);
	ExecuteScript("alarmgoesoff",oAlarm2);	
	ExecuteScript("alarmgoesoff",oAlarm1);
	}



I'm not sure why I couldn't just use "GetLocalObject" and get the string out of where i stored it but it wouldn't let me... i had to get it out as a string then "get object by tag" with the variable, as you can see in the code. anyone know why? I've used "GETLOCALOBJECT" before without problem...

#3
Morbane

Morbane
  • Members
  • 1 883 messages
I think you have to SetGlobalObject() somewhere first - but I havent used object variables very much.

edit:I think you have to SetLocalObject() somewhere first - but I havent used object variables very much. oops :whistle:

Modifié par Morbane, 26 juillet 2010 - 10:20 .


#4
MasterChanger

MasterChanger
  • Members
  • 686 messages

MammonTheViscount wrote...

I'm not sure why I couldn't just use "GetLocalObject" and get the string out of where i stored it but it wouldn't let me... i had to get it out as a string then "get object by tag" with the variable, as you can see in the code. anyone know why? I've used "GETLOCALOBJECT" before without problem...


You should show where you SetLocalObject so we can make sure that you're setting it right. That would be my first guess as to what the problem would be if GetLocalObject isn't working as you expect.

#5
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages
Easy fix.  You have:

object oAlarm2 = GetLocalObject(oAlarm1,"LINKED_OBJECT").     //get object 

with a . at the end of the line instead of a ;

change that up and it should work fine

#6
MammonTheViscount

MammonTheViscount
  • Members
  • 35 messages

Shaun the Crazy One wrote...

Easy fix.  You have:

object oAlarm2 = GetLocalObject(oAlarm1,"LINKED_OBJECT").     //get object 

with a . at the end of the line instead of a ;

change that up and it should work fine


doh :sick:

#7
Shallina

Shallina
  • Members
  • 1 011 messages
GetLocalObject(oAlarm1,"LINKED_OBJECT").



"LINKED_OBJECT" is a string not an object, so this can"t work. It's beceause of the "



You have to pass an object in parameter.

#8
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
@Shallina: no, it's written right. You need a string parameter for the name of the local variable, whether it be a integer, object, or another string.



I'm guessing the problem here is with the code that sets the local object (SetLocalObject), or maybe the name of the variable, "LINKED_OBJECT", which might be used by the engine elsewhere. OEI variables tend to be all-caps like that, I'd use another format just to avoid conflicts.

#9
Shallina

Shallina
  • Members
  • 1 011 messages
GetLocalObject(oAlarm1,"LINKED_OBJECT") ;

instead of GetLocalObject(oAlarm1,"LINKED_OBJECT").

it's a ";" not a "." I think he figured it out by now :P

Modifié par Shallina, 27 juillet 2010 - 11:11 .