Looking for Set Object Interaction script [SOLVED]

Started by Anarcho, Wed 19/01/2005 04:28:59

Previous topic - Next topic

Anarcho

I'm trying to figure out the script to reset an object's interaction...so that I can put it in a run script following a dialogue option.  Specifically, a door is normally locked, but after my character talks to a certain person, I want the door to be unlocked.  I'm going to put it in the dialogue_request function.  I've looked through the index of functions but can't seem to find it.


Candle

This is the commands I found to work with the dialogue .
Code: ags

The dialog commands available are: 

add-inv X 
Adds inventory item X to the current player's inventory. This does the same thing as the AddInventory text script command, but is provided here because it is frequently used in dialogs. 
give-score X 
Gives the player X points, and plays the score sound if appropriate. 
goto-dialog X 
Switches the current topic to Topic X, and displays the current list of choices for that topic. 
goto-previous 
Returns to the previous topic that this one was called from. 
lose-inv X 
Removes inventory item X from the current player's inventory. This does the same thing as the LoseInventory text script command, but is provided here because it is frequently used in dialogs. 
new-room X 
Takes the player to room X, and aborts the conversation. Since this does not allow you to specify co-ordinates, you may need to use some Player Enters Screen logic in the target screen to place the character properly. 
option-off X 
Turns option X for the current topic off, meaning it won't be displayed in the list of choices next time. 
option-off-forever X 
Turns option X off permanently. It will never again be displayed, not even if an "option-on" command is used. 
option-on X 
Turns option X for the current topic on, including it in the list of choices to the player next time they are displayed. 
play-sound X 
Plays sound effect X, similar to the Play Sound interaction command. 
return
Stops the script and returns to the list of choices. 
run-script X 
Runs global text script function "dialog_request", with X passed as the single parameter. This allows you to do more advanced things in a dialog that are not supported as part of the dialog script. The "dialog_request" function should be placed in your game's global script file, as follows: 

  function dialog_request (int xvalue) {
    // your code here
  }
  
set-globalint GI VAL 
Changes text script GlobalInt number GI to have the value VAL. This is equivalent to the SetGlobalInt text script command, and allows you to quickly set things without having to go through a run-script just to set an int value. 
set-speech-view NAME X 
Changes character NAME's talking view to X. NAME must be their script name, and X is the number of the new talking view. Use this to easily change their facial expression during a conversation. 
stop 
Stops the conversation and returns the player to the game. 
For an example of a dialog script, load the demo game into the editor and look at the script for its topic 0.

Anarcho

Yeah, I'm going to use run script x in the dialogue script once I know what the script function would be, as I'm pretty sure there isn't a specific dialogue command to do it.  But I'm not sure what the script would be to do this. 


Candle

Well maybe someone will come along and help you that knows how to do the script as I don't know it very good .

strazer

If the door is in another room than the character, it's best to use a GlobalInt that stores if you have talked to the character or not, then run the object interaction depending on that.

You can set GlobalInts directly in the dialog script when the player chooses the correct dialog option:
...
@2 // dialog option 2
player: How do I get there?
man: Just go through the back door in the yard.
player: Hm, okay, I'll try that.
set-globalint 77 1
...

Then, in the door interaction:

Code: ags

// script for interaction with door
//...

  if (GetGlobalInt(77) == 0) { // if player hasn't talked to MAN yet (GlobalInts are initially 0)
    DisplaySpeech(EGO, "Damn, it's locked.");
  }
  else { // if player has talked to MAN
    if (GetGlobalInt(77) == 1) { // if first time going through door
      DisplaySpeech(EGO, "Hey, it's open!");
      SetGlobalInt(77, 2); // don't display speech next time player goes through door
    }
    NewRoom(4); // go through door into next room
  }

//...

Candle


Anarcho

#6
Cool!  Thanks a bunch strazer.  I actually added a few things, this is what I've come up with:

  // script for object0: Interact object

MoveCharacterBlocking(EGO, 81, 108, 0);

  if (GetGlobalInt(77) == 0) { // if player hasn't talked to MAN yet (GlobalInts are initially 0)
    DisplaySpeech(EGO, "It's locked.");
  }
  else { // if player has talked to MAN
      SetGlobalInt(77, 2); // opens door
      SetObjectView(0,7);
      AnimateObjectEx(0,0,5,0,0,1);
    }
    NewRoomEx (9,300,76); // go through door into next room
  }




Plus it actually worked.  One other question though...next time I do something like this, I just have to use a different number as the globalInt?  Like 78 or something?  What are the numbers I can use?




strazer

You're welcome. :)

But with your code, you can go through the door even if it's locked, right?
I have indented your code properly and color-coded it to show you:

// script for object0: Interact object

  MoveCharacterBlocking(EGO, 81, 108, 0);

  if (GetGlobalInt(77) == 0) { // if player hasn't talked to MAN yet (GlobalInts are initially 0)
    DisplaySpeech(EGO, "It's locked.");
  }
  else { // if player has talked to MAN
    SetGlobalInt(77, 2); // opens door
    SetObjectView(0,7);
    AnimateObjectEx(0,0,5,0,0,1);
  }

  NewRoomEx (9,300,76); // go through door into next room

} // <- end script brace?

Put the NewRoomEx command directly after AnimateObjectEx so it gets executed only if the door isn't locked.

Also, with this you don't need the
  SetGlobalInt(77, 2); // opens door
line. You already set the GlobalInt to something other than 0 (namely 1) in your dialog script.

Quotenext time I do something like this, I just have to use a different number as the globalInt?  Like 78 or something?  What are the numbers I can use?

Yes, use different GlobalInts for different game milestones, as I like to call them.
I used GlobalInt 77 for my example, but it's just an arbitrary number. Currently, there are 500 available GlobalInts, from index 0 to 499.

Anarcho

Ok, I just used the "SetGlobalInt(77, 2);" because it was in your original code, but I'll take it out.

I'm gonna test now, but looks like it all works fine.  Thanks again.



strazer

QuoteOk, I just used the "SetGlobalInt(77, 2);" because it was in your original code, but I'll take it out.

Yes, I used it in my first example to not have the character say "Hey, it's open!" again.
Since you don't want that speech anyway, you don't need to set the GI to 2.
I hope this makes it more clear:

Code: ags

  if (GetGlobalInt(77) == 0) { // if GI 77 is 0
    // part A
  }
  else { // if GI 77 is NOT 0, i.e. it is 1 OR 2

    if (GetGlobalInt(77) == 1) { // if GI 77 is 1 (NOT 0, NOT 2)
      // part B:
      SetGlobalInt(77, 2); // set GI 77 to 2 so neither A nor B gets executed next time
    }

    // part C: gets executed if GI 77 is NOT 0, i.e. it is 1 OR 2

  }


Anyway, I'm glad it works now.

SMF spam blocked by CleanTalk