Having trouble finding scripting help on making gate.

Started by Daniel_1988, Thu 16/10/2008 09:13:03

Previous topic - Next topic

Daniel_1988

I'm making a very basic game, it's a first person-point and click type thing using hotspots to change rooms.
But now I am to where I need a gate. I need to have a key open the lock, then the gate open or disappear. Only thing after the gate is a hotspot to change rooms.
I have a key Inv item, and a lock object. I suppose the gate needs to be an object too?

Basically a hotspot behind the gate. The gate should be an object so It can be removed to show the hot spot behind it? Then the Lock Object will be on top of the gate object. I need to know how to get the key item to interact with the lock and remove the gate, to reveal the hotspot.

:( I can't find a tutorial on this. If someone could link me to something in the right way on like Object and Item interactions. I'm not sure what to do on the gate.

Heh this is probably really easy for you guys. I looked at some of the in progress games and they make me feel like an idiot!

Khris

Break down the problem into parts and solve them one by one:

-Make the gate an object.
-If the key is used on the lock, turn the lock invisible.
-If the gate is clicked, check for the lock's visibility and either display "The gate is locked." or open it / turn it invisible.
-if the exit hotspot is clicked, check for the gate's status and display "The gate is in the way." or change rooms.

You'll need Object.Visible.

Do the manual's tutorial first, it should explain pretty much all of the above.

Daniel_1988

#2
I have been reading tutorials! maybe I'm not looking in the right place. Under scripting there is very little and when I look up object stuff I don't see what I need.

I was actually doing this right before you posted, But got stuck at "If the gate is clicked, check for the lock's visibility" What would the script be to check if the lock is gone?

function Gate_AnyClick()
{
if(object[1].Visible = false)
object[0].Visible = false;
}

This is the only thing I can think of and it doesn't work L((

But if it did work, Would I be able to click on a hotspot behind it? As it's "invisible" not removed.

Mazoliin

First: The solution to your problem:

if (object[1].Visible == false)

In order to check if something has a sertain value you have to use '=='.

Second:
The tutorial KhrisMUC is talking about is the step by step one that's found in the beginning of the manual. Practically the first thing you read. If that's not enough there's also some youtube tutorials on how to use AGS.

Khris

You're almost there, the comparison operator is "==", not "=".

Also keep in mind that you can assign scriptnames to objects, hotspots, etc., making the code more readable.
If you haven't scripted before, now's the time to learn correct indentation:
Code: ags
function Gate_AnyClick() {
  if (Lock.Visible == false) {
    Gate.Visible = false;
  }
}

(Note that neither indenting nor putting {} around a single command after the if is a must. It comes down to taste. But indenting will increase readability and eliminate bugs before they even occur.)

Neutron

a way I have done locking doors, is, to have the locked area cut off from other walkable areas, and add a new walkable area, bridging the gap, when the key is used on it.  I usually try to locate my key cunningly on a nearby path.

Khris

This thread is about a first-person game that uses clicks on hotspots to trigger room changes.

Daniel_1988

I have read the tutorial(maybe I'm missing something?), and watched every youtube video by one guy. The youtube videos were very basic. Thanks a TON for helping, I'm sure there are tons of questions like this from people who didn't read the tutorial.

I think it will work how I have it, But I'm getting an parse error On line 5.

function Lock_UseInv() {
  if(player.ActiveInventory == iKey){
    Lock.Visible == false;
}

I wouldn't bother posting it, but since were on the subject.

TwinMoon

That should be Lock.Visible = false;  (with only one =)

When you're setting a value, use =,
when you're checking a value use ==.

Daniel_1988


Daniel_1988

function Lock_UseInv() {
  if (player.ActiveInventory == iKey){
    Lock.Visible = false;
}

function Gate_AnyClick() {   Getting and error on this line saying Nesting Functions not
if (Lock.Visible == false)                                                                                     supported
    Gate.Visible = false;
}

TwinMoon

That's right. Every time you use a { you must also use a } to close it:

Code: ags

function Lock_UseInv() {
  if (player.ActiveInventory == iKey){
    Lock.Visible = false;
  }
}

Daniel_1988

To save some further post, what do they do and where do they need to go?
I've messed with them some but nothing has changed.

I've just been copying and pasting them out of tutorials.
It didn't throw an error on the first one and it's exactly the same.

Khris

Their basic use is to group together single commands.

Say you want to do this:
if (ItsRaining == true)
  player.GetsWet();
If you're not going to call any other commands than GetsWet that depend on the condition being true, you don't need the curly brackets.

But say in case it's raining, you want the player to bring an umbrella and a jacket, you have to group the commands together:
if (ItsRaining == true) {
  player.AddInventory(iUmbrella);
  player.AddInventory(iJacket);
  jacket_is_worn = true;
}
Omitting the brackets will still add the umbrella to the inventory only if it's raining, but every subsequent command will be called regardless of the condition being true or false, so to avoid that, the commands are grouped together.

It's the same with functions; a function is a set of instructions, so the computer needs to know which ones, that's why you surround the set with brackets.

SMF spam blocked by CleanTalk