Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Caption not working  (Read 3861 times)

0 Members and 1 Guest are viewing this topic.

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Caption not working
« on: October 27, 2015, 05:05:37 PM »

Hi guys,

this probably has a pretty simple answer.
So i have an interface icon (a window) and in the window's script, the following script:
Code: [Select]
on "LeftClick"
{
Game.SelectedItem = "item1";
}

What i want is the user to select one specific item via that window/icon, instead of via the inventory window (though in the current state, it can select it via both).

My problem is this: if I select the item from the inventory window, it is attached to the mouse cursor ad when over an object, the caption displays correctly.
However, if I select the item via the icon(by left clicking on the window that I talked about above), the item gets attached to the mouse cursor, but when it is over another object, there is no caption.

What am I missing? :D
« Last Edit: October 27, 2015, 05:29:58 PM by mihaipuiucernea »
Logged

NAItReIN

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 68
    • View Profile
Re: Caption not working
« Reply #1 on: October 27, 2015, 06:22:01 PM »

Hello,
you should open game_loop.script and  look how does caption work.
Logged

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Re: Caption not working
« Reply #2 on: October 27, 2015, 06:38:29 PM »

Hi,

There's nothing wrong with how it works. Basically, if an item is not selected, then the caption will be either not visible or the text of the current active object.

If an item is selected, the code is this:
Code: [Select]
WinCaption.Text = "Use " + Item.Caption + " with " + ActObj.Caption;with Item, being a variable that stores the Game.SelectedItem.

So it should work, but it doesn't. That's my problem.
« Last Edit: October 27, 2015, 09:10:48 PM by mihaipuiucernea »
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Caption not working
« Reply #3 on: October 27, 2015, 09:48:58 PM »

I think what you are doing wrong is assigning the string "item1" to Game.SelectedItem. You should assign it an Item object:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.         Game.SelectedItem = Game.GetItem("item1");
  4. }
  5.  
Logged

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Re: Caption not working
« Reply #4 on: October 27, 2015, 10:26:36 PM »

I don't think the left click even from the window's script is the problem. Your code will add the item to my inventory, but I already have the item in the inventory.
Let's say item1 is a book. The player has the book in the inventory at the beginning of the game.

And there is an icon in the upper left corner of the screen, which is a window entity with a pic of the book.
The player can use the book either by clicking on the book in the inventory and then use it on various entities in the room, or by clicking on the upper left icon of the book.

The code for the window's script is
Code: [Select]
on "LeftClick"
{
        Game.SelectedItem = "book";
}
So when the player clicks on the icon(on the window entity), the game knows that you have selected an inventory item: the book.

My problem is this: if the player uses the book from the inventory, there are no problems - the captions work as expected from the gameloop script. 
However, if the player uses the book by clicking on the upper left icon(the window entity), it can still use the book item, but there are no captions displayed (example: use book with item).
And I don't understand why the standard floating caption (as defined in gameloop script) only works when i select the item from the inventory, not when i select it via the icon.
« Last Edit: October 27, 2015, 10:30:00 PM by mihaipuiucernea »
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Caption not working
« Reply #5 on: October 28, 2015, 07:55:02 PM »

After testing this, my code would achieve the same result as your code.

Game.GetItem("item1") does not add the item to the inventory, it returns an object of type Item. Game.TakeItem() is the function that adds an item to the inventory.

Nevertheless your code works, it seems Game.SelectedItem accepts both objects and strings.

To better investigate the issue, I suggest that you add Game.Msg:

Code: WME Script
  1. Game.Msg("Debug: " + Item.Caption);
  2. WinCaption.Text = "Use " + Item.Caption + " with " + ActObj.Caption;
  3.  

If you can't see the message (in debug mode it is displayed at the left of the screen) then I suggest that you add Game.Msg in other parts of game_loop.script. I suggest that you add it after the if statements to try and find what is going on.
Logged

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Re: Caption not working
« Reply #6 on: October 29, 2015, 01:25:25 PM »

Hi,

My bad about Game.GetItem, i mistook it for TakeItem.

Anyway, I tried debugging with Game.Msg, but unfortunately I didn't learn anything useful.
Yes, I can see the message and it displays the currently selected item's caption, both when i select the item from the inventory or via the icon(window entity) at the top left of the screen.

But the WinCaption window only works when selecting the item from the inventory. So I know that the item is correctly selected if I use the icon, but I still don't know why the caption only works when selecting the item from the inventory.
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Caption not working
« Reply #7 on: October 30, 2015, 09:24:38 AM »

It's difficult to say without seeing the scripts but it should work. We had something similar with an object that could be used only from an hotspot on the scene and it worked with no problems.
As anarchist said you should try to debug using Game.Msg. Try to see where the script stop first, start to understand if the caption window is displayed for example (where there is "WinCaption.Visible = true;").
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Caption not working
« Reply #8 on: October 30, 2015, 09:35:30 PM »

Yes I think we need to see your game_loop.script to help you further.
Logged

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Re: Caption not working
« Reply #9 on: November 01, 2015, 12:11:30 AM »

The game_loop.script is the standard script, I didn't modify it. As Azrael said, it should work, but I don't understand why it doesn't.

Anyway here is how the caption is treated in the standard game_loop.script
Code: [Select]
// handle the standard foating caption
  if(Game.Interactive && ActObj!=null)
  {
    if (Game.SelectedItem==null)
    {
      WinCaption.X = Game.MouseX;
      WinCaption.Y = Game.MouseY + 20;
      WinCaption.TextAlign = TAL_LEFT;
      WinCaption.Text = ActObj.Caption;

      // keep the caption on screen
      WinCaption.SizeToFit();
      if(WinCaption.X + WinCaption.Width > Game.ScreenWidth) WinCaption.X = Game.ScreenWidth - WinCaption.Width;
      if(WinCaption.Y + WinCaption.Height > Game.ScreenHeight) WinCaption.Y = Game.ScreenHeight - WinCaption.Height;
  }
    // handle the caption when you want to use an object with another
    else {
      var Item = Game.SelectedItem;

      WinCaption.X = 0;
      WinCaption.Y = 684;
      WinCaption.Width = Game.ScreenWidth;
      WinCaption.TextAlign = TAL_CENTER;
      WinCaption.Text = "Use " + Item.Caption + " with " + ActObj.Caption;
    }
    WinCaption.Visible = true;
    WinCaption.Focus();
  }
  else WinCaption.Visible = false;

But it only works when I use the object from the inventory. If I try to use it from the GUI icon, there's no caption.

I think I'm just going to code a new caption, for the case in which the item is selected via the icon. If anyone might have a clue as to why it's not working, let me know.

Edit: I also tried what Azrael said: having a hotspot in a scene and when i click on the hotspot, Game.SelectedItem = "item". The caption doesn't work in this case either. It's interesting :D
« Last Edit: November 01, 2015, 12:48:33 AM by mihaipuiucernea »
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Caption not working
« Reply #10 on: November 03, 2015, 09:15:35 AM »

I tried making a new project and it worked without problems, so there should be something in your scripts.
I don't see anything wrong in your game_loop.script, maybe somewhere else?

Anyway as i said before you have to try to understand where the script stop. The caption script have some "if", try to see if everything work with "Game.Msg", it help me a lot during the development.
Logged

NAItReIN

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 68
    • View Profile
Re: Caption not working
« Reply #11 on: November 03, 2015, 02:03:17 PM »

I made a new project and everything was OK! I really don´t understand what´s wrong in your case.
« Last Edit: November 04, 2015, 12:45:52 AM by NAItReIN »
Logged
 

Page created in 0.03 seconds with 20 queries.