How to run a specific script linked to only the FIRST Click on an Object? Solved

Started by marbar, Wed 16/12/2009 04:35:02

Previous topic - Next topic

marbar

Hello,

this is what I want to do:

My main character shall look and interact with several objects after the cutscene. Before he hasn't done all this he must not got to bed. After he has done all the relevant interactions he can use his bed now.

So, that's what I've tried so far:

I've created a new global vint ariable. Every time my player cínteracts with a relevant object in any way (Look, Talk, Use), a 1 is added to the value of the global variable. There are 5 objects so the max value should be 15. Now I've set in my bed function that if this variable value exceeds 15 the player can use his bed and go to sleep.

This works, but the actual problem ist, that the variable value is independent of the specific interactions so far, that is the value of 15 can be reached by just clicking 15 times on any object in any mode. But this is not what I want. I want my character to interact with every object in every possible mode, and this would be the condition to let him go to bed.

Now, is there a way to link my global variable to just the FIRST object interaction? Or do I have to solve this problem in a completely different way?




Ghost

Simplest way is the DoOnceOnly() command, as seen here:
http://www.adventuregamestudio.co.uk/manual/Game.DoOnceOnly.htm

This allows to to have each of your objects add the 1 to your counter ONLY ONCE. I bet there is a more elegant way to script the whole thing, but DoOnceOnly should serve you well already.

marbar

Ok, Thx, it worked fine

....if I knew there's such a command....I mean I find it hard to find a relevent command in the manual if you don't know its name or something specific....and a search with a keyword is also not so simple, there aren't much keywords to use besides commands and very specific words...
i always try to solve a problem on my own but if you don't have enough epertise it's quiet hard sometimes even witz the smallest steps...

that's why i have to use this forum so often. i hope it's ok...:)

Bye and thx again!

suicidal pencil

Quote from: Ghost on Wed 16/12/2009 04:39:49
I bet there is a more elegant way to script the whole thing...

a Ternary Operator and a quick function call would do it...if AGS supported them.

However, DoOnlyOnce() is perfect :)

Ghost

Quote from: marbar on Wed 16/12/2009 05:41:33
....if I knew there's such a command....I mean I find it hard to find a relevent command in the manual if you don't know its name or something specific....

Depending on your background the manual *can* be a bit unwieldy, but a good idea is to check the game object that is affected (like Inventory, Object, Hotspot) for useful commands. With more generic (game) commands it *is* harder. I remember how thrilled I was when DoOnceOnly was mentioned in the upgrade section... but if I'd be new to scripting, I wouldn't have discovered it on my own very fast ;)

The totally GEEKY way would be to check the readme of AGS for all its updated commands. Believe me, it's a thrill ride!

Calin Leafshade

I wish i'd known about that command.. wouldve avoided alot of pointless boolean globals.

hedgefield

Darn that is a useful piece of code! Didn't know about that, thanks.

SMF spam blocked by CleanTalk