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: Saved games and inventory  (Read 4323 times)

0 Members and 1 Guest are viewing this topic.

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Saved games and inventory
« on: May 25, 2006, 08:24:23 AM »

Hi,

I recognized that when I save a game, then change something in one of the inventory scripts and reload the game, the changes in the inventory scripts are not active. That means that if I found an inventory concerning bug in my game and kill it, all the save games are for the trashcan. The same thing with changed inventory images.
Are the item things saved completely in the save games? Is there something I can do about it? Something like an "inventory.reset()" to call before loading a game?

Thanks in advance.
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Saved games and inventory
« Reply #1 on: May 25, 2006, 11:08:41 AM »

Well all currently running scripts are saved and restored. As inventory items are created, their scripts get executed and hence they're saved.
The only way to "reset" a script would be to unload it using DetachScript() and reload it by AttachScript().
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Saved games and inventory
« Reply #2 on: May 25, 2006, 11:44:03 AM »

I see. That would mean: I have to query each item defined in the "items.items" file, detach its script and attach each script again. That makes some work with over 100 inventory items. Is there a chance of adding some method to the engine itself, that does that automatically? Not now, but in the anytime in the future?

Thanks
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Saved games and inventory
« Reply #3 on: May 25, 2006, 04:13:12 PM »

It shouldn't be hard to make a script which loops through all the inventory items and restarts their scripts, providing that the scripts' names are equal to item names, for example.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Saved games and inventory
« Reply #4 on: May 28, 2006, 11:58:03 PM »

Hi,

I tried this piece of code in the game.script:
Code: [Select]
////////////////////////////////////////////////////////////////////////////////
on "AfterLoad"
{
     // Workaround for Inventory
     var TempItem;
     var Status;
     for(var t=0; t<=Game.TotalNumItems-1; t=t+1) {
       TempItem=Game.QueryItem(t);
       if(TempItem!=null) {
          Status=TempItem.DetachScript("items\scripts\"+TempItem.Name+".script");
          Game.LOG(TempItem.Name+" detached: "+Status);
          TempItem.AttachScript("items\scripts\"+TempItem.Name+".script");
       }
     }
}

But the re-attaching of the scripts doesn't seem to work. The log file says the following:
Code: [Select]
00:48: Loading game 'saves\save000.dsv'...
00:48: Sand detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\Sand.script' mutiple times (obj: 'Sand')
00:48: Zahnbürste detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\Zahnbürste.script' mutiple times (obj: 'Zahnbürste')
00:48: Zahnpasta detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\Zahnpasta.script' mutiple times (obj: 'Zahnpasta')
00:48: W.O.E. Fahrkarte detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\W.O.E. Fahrkarte.script' mutiple times (obj: 'W.O.E. Fahrkarte')
00:48: Geld detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\Geld.script' mutiple times (obj: 'Geld')
00:48: Stein detached: yes
00:48: CBScriptHolder::AddScript - trying to add script 'items\scripts\Stein.script' mutiple times (obj: 'Stein')
.
.
.
and so on

Does anyone have an idea what is going wrong?

Thanks in advance.
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Saved games and inventory
« Reply #5 on: May 29, 2006, 11:49:58 AM »

Mhm, the problem is that script detachment is delayed. When you call DetachScript, it's only marked to be detached and it's physically detached later. That's why the subsequent call to Detach and Attach has no effect..
Well, perhaps some native object.RestartScripts() method would be the best solution here..
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Saved games and inventory
« Reply #6 on: May 29, 2006, 04:23:34 PM »

Hi,

Quote
When you call DetachScript, it's only marked to be detached and it's physically detached later.

When is it physically detached? Could I help myself for now by detaching the scripts, keep the names of the items in an array and reload them when the time is due? (a native method would of course be appreciated  ;))

Thanks
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Saved games and inventory
« Reply #7 on: May 29, 2006, 07:19:04 PM »

You can download WME latest which no longer complains when you try to reattach a script which is marked for detaching.
« Last Edit: May 29, 2006, 07:21:25 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Saved games and inventory
« Reply #8 on: May 30, 2006, 06:39:54 PM »

Thanks Mnemonic. This will help.

Mac

Logged
 

Page created in 0.095 seconds with 23 queries.