Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Modify inventory behaviour  (Read 4588 times)

0 Members and 1 Guest are viewing this topic.

VonDoom

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
    • View Profile
Modify inventory behaviour
« on: November 05, 2009, 11:23:19 PM »

Hi

 I'm designing a game where the character has 2 inventories. One of them is a normal inventory but you can't use it to interact with things on the game, it's just to check and combine things. The other one is exclusively for interacting with stuff on the real world so every object in it works like a button (you can't drag them or examine them). Both of them have the same objects so instead of having two inventories maybe it could be achieved with one inventory and 2 different ways to present it.

 So is there anyway to modify that in an inventory? Because I can't seem to find any script in the project manager managing inventory behaviour. I know that in inventory.def there is an option to associate a script to the inventory but i haven't found any info in the help file regarding inventory programming.

 To sum it up: HaLp!!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Modify inventory behaviour
« Reply #1 on: November 06, 2009, 12:04:15 PM »

The built-in inventory system functionality is pretty much fixed. If you need to do something very different, you'd need to reimplement the inventory from scratch, using GUI windows / buttons etc. I think it's doable, and it's been discussed here numerous times, but I haven't seen anyone actually doing that.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

VonDoom

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
    • View Profile
Re: Modify inventory behaviour
« Reply #2 on: November 06, 2009, 03:17:33 PM »

Thanks, I'll give it a try myself. I already have a couple of ideas on how to do it, I'll let you know if I manage to work it out in case anybody is interested.

By the way, do you remember any of those threads? They might give me some clues

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Modify inventory behaviour
« Reply #3 on: November 06, 2009, 03:21:04 PM »

Some basic info is here. Not much though :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

VonDoom

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
    • View Profile
Re: Modify inventory behaviour
« Reply #4 on: November 07, 2009, 02:58:44 PM »

As most things when it comes to programming this turned out to be surprisingly simple. First I create a window with the exact number of buttons as items my inventory is going to contain in the whole game. Each of this buttons must have the same name as the items.

Then, when I call the window, I organize each button according to the order in which the items appear in the inventory:

Code: [Select]
  var xpos=15;
 
  for(var i=0; i<Game.NumItems; i=i+1)
  {
var nombre = Game.GetItem(i);
var prov = Invenbut.GetControl(nombre.Name);
prov.SkipTo(xpos,prov.Y);
xpos=xpos+65;
  }

I still have to make sure I hide the buttons that are not yet in the inventory and show the ones that are. I'm a bit stuck there because the only thing I can think of is creating an array with all the buttons names, creating a second array with all the inventory items names, substract the second array from the first array and make the resulting buttons visible. It's a bit of a headache so if anyone can think of a more efficient way to do it please let me know.
Logged

VonDoom

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
    • View Profile
Re: Modify inventory behaviour
« Reply #5 on: November 07, 2009, 07:27:36 PM »

Hi, just a question, is there any method that lists authomatically all the buttons in a window and returns either the index or the name of the buttons as an array? Probably not, but just in case.

Edit:

Nevermind, it's already done. If anyone wants to know how I did it just reply and I'll post the code.
« Last Edit: November 07, 2009, 09:42:28 PM by VonDoom »
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Modify inventory behaviour
« Reply #6 on: November 07, 2009, 09:42:46 PM »

you mean something like this?

Code: WME Script
  1. var a = 0;
  2.  
  3. while(1)
  4. {
  5.   var e=yourWindow.GetControl(a);
  6.   if (e==null) break;
  7.   a = a+1;
  8. }
  9.  
  10.  

this code returns all window components. You can then easily test for button e.Type == "button"

My approach though goes with indexed naming. I name buttons eg. but_1, but_2 etc... Then I reference them through

Code: WME Script
  1. var index = 0;
  2. var e = window.GetControl("but_"+index);
  3.  
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Modify inventory behaviour
« Reply #7 on: November 07, 2009, 09:50:58 PM »

Or

Code: WME Script
  1. for (var i = 0; i < window.NumControls; i = i + 1)
  2. {
  3.   var someControl = window.GetControl(i);
  4. }
  5.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

VonDoom

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
    • View Profile
Re: Modify inventory behaviour
« Reply #8 on: November 07, 2009, 10:04:01 PM »

 I used the same method as Mnemonic, but I'll try to remember yours as well, metamorphium.

 My programming skills are somewhat rusty so right now there are things I could never come up with. For example, I would have never thought I could manually break out of a loop with a break statement (I really should finish reading the help files but it's going to take some time).

Thanks guys.
Logged
 

Page created in 0.051 seconds with 25 queries.