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: Item Interactions don't work as expected  (Read 7295 times)

0 Members and 1 Guest are viewing this topic.

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Item Interactions don't work as expected
« on: August 22, 2009, 04:44:25 PM »

Hello, I am now scripting item combinations and I ran into several problems. When I want to do:

Code: WME Script
  1. on "wired_battery"
  2. {
  3.         Game.Interactive = false;
  4.         actor.Talk("If I attach the battery to the solar panels I may be able to charge it.", "");
  5.         Game.Interactive = true;
  6.        
  7.         Game.TakeItem("solar_battery");
  8.         Game.DeleteItem("solar_panels");
  9.         Game.DeleteItem("wired_battery");
  10.        
  11.         Game.Interactive = false;
  12.         actor.Talk("Fits nicely. It should charge up anytime now...", "");
  13.         Game.Interactive = true;
  14. }
  15.  

What happens here: The Actor Talks the first line, then he gets the item solar_battery
But the deletion of the items does not work and he wont say the second line.

Then I tried this:


Code: WME Script
  1. on "wired_battery"
  2. {
  3.         Game.Interactive = false;
  4.         actor.Talk("If I attach the battery to the solar panels I may be able to charge it.", "");
  5.        
  6.         Game.TakeItem("solar_battery");
  7.         Game.DeleteItem("solar_panels");
  8.         Game.DeleteItem("wired_battery");
  9.  
  10.         actor.Talk("Fits nicely. It should charge up anytime now...", "");
  11.         Game.Interactive = true;
  12. }
  13.  

In this case the actor says his first line, and then the game is stuck with the wait cursor and nothing else happens (no item or second talk line or anything).


When I code it without the Game.Interactive lines then it works fine but of course only if you don't skip any lines. If you skip a line, the player wont get the items or the delete of the specified items will be only partial.


How exactly do you code it properly and what is my mistake?
« Last Edit: August 22, 2009, 04:46:44 PM by Darky »
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Item Interactions don't work as expected
« Reply #1 on: August 23, 2009, 04:00:45 AM »

actor.Talk("If I attach the battery to the solar panels I may be able to charge it.", "");

I'm just curious.  Why do you have the , ""?

instead of

actor.Talk("If I attach the battery to the solar panels I may be able to charge it.");

Again, I'm just curious--I've never done it the way you did it.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Item Interactions don't work as expected
« Reply #2 on: August 23, 2009, 09:21:55 AM »

The script is attached to "solar_panels" item, right? So once you call the

  Game.DeleteItem("solar_panels");

line, the game will erase the item, together with the attached script. That's why the lines following that one won't be executed. Basically, just move the DeleteItem line to the end of the block and it will work as expected.

I know it's far from ideal, it confuses people a lot.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Item Interactions don't work as expected
« Reply #3 on: August 23, 2009, 09:23:16 AM »

if you called DeleteItem, you also delete the script you're right now executing. So move the delete item command of the item which belongs to this script as a VERY LAST line of the method.

Edit: Mnemonic beat me to it. :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Item Interactions don't work as expected
« Reply #4 on: August 23, 2009, 11:20:12 AM »

Thanks Guys, I see... it really is that simple. Okay, it works now :)

How do you Guys handle your Item Interactions by the way? At the moment I code the same stuff in both items so if the Player moves the Battery on the Solar Panels it will combine the items and if he moves the Solar Panels on the Battery it will do just the same. Is there some way to "ease" that a bit? Because if I do changes in one I have to be careful to think of changing the other one as well and it can get very confusing as the amount of items grows. I was just wondering?


@Catacomber:
I do it that way because the Debug then gives me an Error of the "could not open sound file" sort. I don't have Strings yet but will add voices to the texts at some later point eventually and I havn't decided their filenames yet, so I leave it with the "" for the case that I might overlook a line while I change things for the strings and audio filenames. At least thats the idea, as sort of a helper, since the "Search in Files" from the Scite Editor doesn't work very well for me...
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: Item Interactions don't work as expected
« Reply #5 on: August 23, 2009, 11:38:46 AM »

why would you do this? WME has sound files autoplay feature.

http://res.dead-code.org/doku.php/faq#qhow_to_work_with_automated_speech_files
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: Item Interactions don't work as expected
« Reply #6 on: August 23, 2009, 12:01:43 PM »

I didn't know about this, I thought you have to do it all manually... thanks for the tip, that saves time! :)
Logged

SaulBetz

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 1
    • View Profile
Re: Item Interactions don't work as expected
« Reply #7 on: February 26, 2014, 11:08:45 AM »

actor.Talk("If I attach the battery to the solar panel I may be able to charge it.", "");

I'm just curious.  Why do you have the , ""?

instead of

actor.Talk("If I attach the battery to the solar panels I may be able to charge it.");

Again, I'm just curious--I've never done it the way you did it.

Is there any proper solution to the query? I have been working a while on this but still not able to find appropriate answer.. Please reply if you can.
« Last Edit: February 27, 2014, 06:03:45 PM by SaulBetz »
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Item Interactions don't work as expected
« Reply #8 on: February 27, 2014, 09:04:59 PM »

How do you Guys handle your Item Interactions by the way? At the moment I code the same stuff in both items so if the Player moves the Battery on the Solar Panels it will combine the items and if he moves the Solar Panels on the Battery it will do just the same. Is there some way to "ease" that a bit? Because if I do changes in one I have to be careful to think of changing the other one as well and it can get very confusing as the amount of items grows. I was just wondering?

If you want to achieve adding the combination code only in one item's script, you can tweak the game.script. I do it this way:

Code: WME Script
  1. else if(Item.CanHandleEvent(ActObj.Name)) Item.ApplyEvent(ActObj.Name);
  2.  

This way the code will be executed either if you combine the solar panels with the battery or vise versa.

The only drawback in this is that you need to remember in which of the two items you added the code, but still it is better than having to modify the code in both items.
Logged
 

Page created in 0.095 seconds with 24 queries.