[Solved] Global Script interrogation

Started by actaria, Wed 07/12/2022 17:30:14

Previous topic - Next topic

actaria

Hello,

I have some problems with a script part in Global Script
It's a usual code i really don't know what i am doing wrong.

The Character needs to get 10 rocks with a pickaxe then give them to a NPC
I also have a GUI that counts the number of rocks top right of the screen

Code: ags
function NPC_UseInv()
{
if (rock10==true)
{
  if (cChar1.ActiveInventory == irock)
  {
    grock10.Visible=false;
    player.LoseInventory(irock); 
    cChar1.Walk(1274, 665, eBlock);
    cChar1.FaceDirection(eDirectionUp);
    cbianca.Say("congrats you made it");   
  }
}

The end of the code i use to show the number of rock GUI
Code: ags
function room_RepExec()
{
if (rocks == 10)
 {
 grock9.Visible=false;
 grock10.Visible=true;
 SetTimer(1,0);
 rock10=true;
 player.LoseInventory(ipickaxe); 
 }
}
I have 3 problems yes that a lot :)
-the GUI stay on screen
-Player is not losing rocks from his inventory
-NPC is not using speech view anymore (it's working in the room script) means no animation and the speech color is white when supposed to be green.

I also use a simple code to randomize if the player get a rock or not but i don't think it's related to the problem.

What am i doing wrong ?
Thanks a lot for your precious help

EDIT:
I removed all the part from the function room_RepExec() and now it's in each hotspot area where the player use the pickaxe it was a big mistake i think.
Now the GUI is being removed as intended, other problems remain the same

EDIT 2:
Ok my code was a toal mess

I was adding a new rock each time in my inventory so i had to click 10 times on ths NPC to see the rock disapear from the inventory.
GUI is also removing well now that it is not on RepExec anymore

I'll see now for the speech color

Khris

You can add an item to the inventory multiple times.
Just call player.AddInventory(iRock); in ten places. If a hotspot is exhausted after getting a rock from it, you obviously need to keep track of that; simply disabling the hotspot is one way, using a custom bool/int property is another.

To update the GUI, you can do this:
Code: ags
function on_event(EventType event, int data)
{
  if (event == eEventAddInventory && data == iRock.ID) {
    lblRockCount.Text = String.Format("%d rocks gathered", player.InventoryQuantity[iRock.ID]);
  }
}

Similarly you can check the quantity when interacting with the NPC:
Code: ags
function NPC_UseInv()
{
  // always check item first, to separate its logic from other items
  if (player.ActiveInventory == iRock) {
    int rocks = player.InventoryQuantity[iRock.ID];
    cChar1.Walk(1274, 665, eBlock);
    cChar1.FaceDirection(eDirectionUp);
    if (rocks >= 10) {
      for (int i = 0; i < rocks; i++) player.LoseInventory(iRock); // lose all
      NPC.Say("Congrats, you made it!");
    }
    else NPC.Say("You haven't gathered enough rocks, you need %d more.", 10 - rocks);
  }
  else player.Say("I don't think they're interested in that.");
}

actaria

Hello Khris,

Thanks for the reply,

This is so much better than the way i was doing to update the GUI.

Same thing for the way you check the quantity given to the NPC

I will keep this script and use it again on another room to be used to count and update GUI the right way.

Everything is working great now the only remaining problem is that the NPC isn't using is Speech and color wiew.

The color is white when he talks (supposed to be green) and the speech animation isn't playing in Global Script when it's working normally in Room Script.

I tried:

cNPC.SpeechView = 61; but it still not animating or changing the text color

I guess it might be another setting set to white somewhere else.

Any idea ?

Thanks so much once again to help me progress with AGS.

Cassiebsg

You probably have it set somewhere else.

Few thing to check:
- Do you have more than 1 character that look the same? Maybe you're using the wrong character?
- Check all lines where cChar1/cbianca (the NPC that isn't working - right click on the name and you should get an option "Find all"). Review each line and make sure you didn't change it's view, or forgot to unlock a view somewhere. or change it's speech color.
There are those who believe that life here began out there...

actaria

#4
Hello Cassiebsg,

Stupid girl i am...
Without having my code you found my mistake.
I was not even using the correct character name but another one that is almost the same.
Thanks a lot  it's been 2 days and i was not even able to see this.

Plus i tried for hours some WalkableArea wondering why my character was not able to go through the way and it was an invisble part of the PNC blocking the way
i just needed a solid=false.

I guess this is how we learn :)

Thanks again you saved me many hours.

Cassiebsg

NP, you're welcome. :)
I've seen ppl do that mistake before, so thought it was worth mentioning it.  ;)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk