[SOLVED] Use specific inv item - and more

Started by Nixxon, Sat 19/05/2012 00:32:36

Previous topic - Next topic

Nixxon

Hi Guys -

two relatively simple questions.

Question 1

How do I specify a SPECIFIC inventory item used on the object? As it stands I can use ANY inventory item on the objects to gain the desired effect :(

I tried putting the inventory ID/script name inside the brackets after UseInv with no success.


function screw1_UseInv()
{
aMetal_Decay.Play();
object[1].Visible = false;
GiveScore(1);
}

function screw2_UseInv()
{
aMetal_Decay.Play();
object[2].Visible = false;
GiveScore(1);
}

function screw3_UseInv()
{
aMetal_Decay.Play();
object[3].Visible = false;
GiveScore(1);
}

function screw4_UseInv()
{
aMetal_Decay.Play();
object[4].Visible = false;
GiveScore(1);
}


Question 2.

Re the script above. Once the player interacts with each object I'd like another object to appear on screen.

As you can see each object is set to false when they're interacted with. Do I use a repeatedly execute function of some sort? Like if Object 1,2,3,4 = false. Then object 5 = true?


I'm getting there....

Really appreciate the help.

Slipshod

#1
For the first question:

Code: AGS

function oScrew_1_UseInv()
{
if (player.ActiveInventory==iSpecificItem)
    {
    aMetal_Decay.Play();
    object[1].Visible = false;
    GiveScore(1);
    }
}


Replacing iSpecificItem with your specific item name.


as for your second:

Code: AGS

function room_RepExec()
{
if ((oObject1.Visible==false) && (oObject2.Visible==false)&& (oObject3.Visible==false)&& (oObject4.Visible==false)) 
{
  
oObject5.Visible=true;

}



This is how I would do it may be a better way. :)

Nixxon

Hi madd,

Thanks for that.

Seems like it should work OK, though now I'm having trouble =

room9.asc(9): Error (line 9): Nested functions not supported (you may have forgotten a closing brace)


What am I doing wrong here?


/ room script file
function room_RepExec()
{
if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false))
{
oObject5.Visible=false;
}

function exitroom_AnyClick()
{
player.ChangeRoom(6, 760, 460);
gGui1.Visible = true;
justinv.Visible = false;
}


function screw1_UseInv()
{
  if (player.ActiveInventory==iKnife)
{
aMetal_Decay.Play();
object[1].Visible = false;
GiveScore(1);
}

function screw2_UseInv()
{
  if (player.ActiveInventory==iKnife)
{
aMetal_Decay.Play();
object[2].Visible = false;
GiveScore(1);
}

monkey0506

What you're doing wrong is going out of your way to mess with the indentation that AGS is already handling automatically. Or so I would assume seeing as you didn't realize you're missing half your closing braces:

Code: ags
// room script file
function room_RepExec()
{
  if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false)) 
  {
    oObject5.Visible=false;
  }
} // ADDED MISSING CLOSING BRACE

function exitroom_AnyClick()
{
  player.ChangeRoom(6, 760, 460);
  gGui1.Visible = true;
  justinv.Visible = false;
}


function screw1_UseInv()
{
  if (player.ActiveInventory==iKnife)
  {
    aMetal_Decay.Play();
    object[1].Visible = false;
    GiveScore(1);
  }
} // ADDED MISSING CLOSING BRACE

function screw2_UseInv()
{
  if (player.ActiveInventory==iKnife)
  {
    aMetal_Decay.Play();
    object[2].Visible = false;
    GiveScore(1);
  }
} // ADDED MISSING CLOSING BRACE


Oh, and it's not technically something wrong, but if this is in the room script, you can use the object's script names directly instead of having to reference them by ID. Makes the code more readable and easier to debug.

Nixxon

Indeed all of my closing brackets were missing :P

The use specific items works great now, thank you!

The repeated execute doesn't seem to work however. After all 4 objects are removed, Object 5 still remains.


function room_RepExec()
{
  if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false))
  {
    oObject5.Visible=false;
  }
}


Any ideas?

Thanks again.

Nixxon

#5
EDIT: We're all good.

Had to add from the events pane.


Thanks again. I'l be back :)

Nixxon

BACK:

Everything's working sweet. However, once object 5 disappears I'd like for a sound to play, and a givescore. THE FIRST TIME only however.

How to i integrate this into the Rep Exec function?

I've tried a few different things -


function room_RepExec()
{
  if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false))
  {
    oObject5.Visible=false;
  }
    if (Game.DoOnceOnly("open mains")) {
    aOpenlock.Play();
    GiveScore(2);

}


The above just gives me a score and plays the sound as soon as I enter the room.

monkey0506

#7
Quote from: Nixxon on Sat 19/05/2012 01:50:34...once object 5 disappears I'd like for a sound to play, and a givescore. THE FIRST TIME only however.

Seeing as you want this to be part of the condition where the object 5 is turned off, why didn't it occur to you to put it inside the braces for that condition? You do understand what those braces are for, yes?

Code: ags
function room_RepExec()
{
  if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false)) 
  {
    oObject5.Visible=false;
    if (Game.DoOnceOnly("open mains"))
    {
      aOpenlock.Play();
      GiveScore(2);
    }
  }
}


Edit: Sorry if the tone sounds a bit condescending, but we were just talking about braces, weren't we? ;)

Nixxon

#8
Quote from: monkey_05_06 on Sat 19/05/2012 03:01:13
Quote from: Nixxon on Sat 19/05/2012 01:50:34...once object 5 disappears I'd like for a sound to play, and a givescore. THE FIRST TIME only however.

Seeing as you want this to be part of the condition where the object 5 is turned off, why didn't it occur to you to put it inside the braces for that condition? You do understand what those braces are for, yes?

Code: ags
function room_RepExec()
{
  if ((screw1.Visible==false) && (screw2.Visible==false)&& (screw3.Visible==false)&& (screw4.Visible==false)) 
  {
    oObject5.Visible=false;
    if (Game.DoOnceOnly("open mains"))
    {
      aOpenlock.Play();
      GiveScore(2);
    }
  }
}


Edit: Sorry if the tone sounds a bit condescending, but we were just talking about braces, weren't we? ;)


i DID that... however as it is in the repeated execute. The sound kept playing, and I kept getting a score on every game loop. :(

EDIT: Just tried your code, works a treat. I really have no idea with all the braces/brackets do. Just shitting in the wind here. :)

monkey0506

Just FYI, no need to quote the entire post just to respond to it. You can quote a specific part of the post if you need, but otherwise it's understood what you're responding to. ;)

As far as the braces, they are there to group a collection of commands together. If you don't include the braces after an if statement, for example, then only the very next command is based on the condition. If you include the braces, then you can run multiple commands conditionally. Functions always have braces.

Code: ags
function room_RepExec()
{ // opening brace for function (required)
  if (condition1) DoSomething(); // if condition1 is true, call the DoSomething function, no braces required
  if (condition2)
  { // opening brace for condition2 (optional)
    DoSomethingElse(); // if condition2 is true, call DoSomethingElse, braces here are optional since it's only one command
  } // closing brace for condition2 (required, matching brace)
  if (condition3)
  { // opening brace for condition3 (required)
    DoSomething();
    DoSomethingElse(); // braces are required since we have two (or more) commands based on condition3
  } // closing brace for condition3 (required, matching brace)
} // closing brace for function (required, matching brace)

Nixxon

^^ that's really cool - makes a bit of sense now :)

Thanks again.

Khris

#11
A bit of sense...?? Jesus.
I'm glad I missed this exchange due to sleeping.

Nixxon, use the forum search before opening a thread! The "how do I specify an inv item" question has been asked and answered countless times before, and so has the "how do I make z happen after player does x and y".
That's the stuff that comes up again and again and again and again and again and again and again and again and again. Didn't it occur to you that maybe somebody else might have had the same problem before...?
Also, quoting the entire previous post, why...?

Don't take this too personal, it just gets to me when somebody's wearing huge blinders like that.

It does motivate me though to finally make that faq where f stands for "all the freaking time", so thanks for that :)

PS: I just noticed that you replied to my mentioning Game.DoOnceOnly in the other thread over one hour before asking basically the exact same thing here. WTF?

Cyrus

BTW, Nick, how are your long lost projects, Jimmy Jam and Duke Stalker (sorry for offtop)?  (laugh)

Gilbert

Quote from: Cyrus on Sat 19/05/2012 15:37:50
(sorry for offtop)

If you really want to know, ask him in PM. DOn't put off topic comments here.  :tongue:

Nixxon

#14
Khris.

Whilst I did an extensive forum search, It's quite hard for us non-coders to apply out of context examples believe it or not.

I did not ask about the function of 'doonceonly' in this thread as it was in my original code (which i'd learn from my other thread - thanks for that :))... it was an issue with the bracers.

I know it can be frustrating and I do apologize. However, there's really no need to be so overzealous. There's more time & energy exhausted in your post than in my threads combined.

This forum doesn't exactly have a high-traffic problem, and I'm beginning to know why.

Things have changed since 2002. :(

Khris

#15
Yeah, I joined in 2004 and really cleaned this place up, single-handedly. Especially all the passive-aggressiveness was a thorn in my side.

Re "extensive forum search":
3rd result when searching for "specific item": http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44986

Nixxon

Quote from: Khris on Sun 20/05/2012 09:38:26Re "extensive forum search":
3rd result when searching for "specific item": http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44986

^^ I stand corrected.

Dude... I'm honestly not trying to be 'douchey' here.

However, It's the equivalent of myself going into the critics lounge and spouting "Where's your light source? WTF?? There a are multiple tutorials online re light sources, don't bother us here. Don't take this too personally" etc.

monkey0506

Yes, it's exactly like that.

Except, you know, the forum rules for the critic's lounge don't state that you should check to see if someone has had a similar issue as your question may have already been answered by others in the same forum.

Khris may have come across a bit harsh, but seriously, braces are one of the single most basic concepts in programming. We're happy to help you out if you have questions, but we're here volunteering our own time to assist you, and teaching basic programming concepts is not exactly the purpose of this forum.

You should check out, at the very least, the scripting tutorial in the manual. And then go through the other tutorial material. And then read the BFAQ questions on the wiki. It will benefit you and your experience here immensely.

Nixxon

More than fair. Actually, I surprised myself by working out global variables with some perusing. An achievement as my stupidity knows no bounds.

geork

I dunno if you have already seen them, but I'd reccomend the densming AGS tutorial videos here:

http://www.youtube.com/watch?v=1Ml_DR76Cl4&list=PL21DB402CB4DAEAEF&feature=plcp

I found them to be very helpful in getting to know my way around (and no, he hasn't paid me to post this ;) )

SMF spam blocked by CleanTalk