Author Topic: Requiring two items in inventory to shot  (Read 7143 times)

jweldon

  • Visitor
  • *
  • Posts: 16
    • View Profile
    • Email
Requiring two items in inventory to shot
« on: 2005-12-08, 07:56:04 AM »
First, let me say that this is a great program.  I've tried several others and this is the first one I've actually been able to create something with!

I'm new to game making and not a scripter.  (I want to learn!)
Looking for a way to require two items in the inventory before I can fire or shoot.
I read the messages between Ben Marty and Dr. Obvious, but I'm still a little fuzy on the code details that were given back.
Here is my situation:
I want my player to find a sling shot on the board and then they can throw rocks at enemies only after collecting rocks and sling shot.  I have figured out how to add then to iventory... Right now I can throw rocks if I have rock in inventory with or without the sling shot in my inventory.
Please help...

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Requiring two items in inventory to shot
« Reply #1 on: 2005-12-08, 08:42:33 AM »
I can think of two solutions, one without script and the other with:

1) No script: Prevent the player from picking up rocks if they haven't picked up the slingshot yet.  I think this can be done by setting the tile interaction for a rock to "Use Item Without Subtracting" and set it to require the player to have a slingshot.  Then the effect would be to replace the tile with an empty tile if the inventory is OK, and activate a function.  The function would be an alter inventory function that adds a rock to the inventory.  The main problem with this solution is that the player will continue to "pick up" rocks (make them disappear from the map) even if he can't hold any more.

2) With script: I don't have the scripting wizard handy at the moment, but I think the scripting wizard can generate a shooting script that uses up inventory when you shoot.  There should be some check like ".InvQuantityOwned(0) > 0" in the script (where "0" represents the index of rocks in the inventory).  If you can find that you could just replace it with ".InvQuantityOwned(0) > 0 and .InvQuantityOwned(1) > 0" (where "1" represents the index of the slingshot in the inventory).  I don't remember the exact syntax that the wizard generates, but basically you just copy the expression that's there, change the index and put an "and" between the two pieces.

Let us know which option you choose and how far this gets you.

jweldon

  • Visitor
  • *
  • Posts: 16
    • View Profile
    • Email
Re: Requiring two items in inventory to shot
« Reply #2 on: 2005-12-08, 09:02:11 AM »
I'm working on the game now, When I go to tile interaction I don't see an option to pick"Use Item Without Subtracting" I only see these 4 choices.  "Add item", "subtract item", "require in inventory", and "no effect on inventory"  I think I have the lattest version of SGDK 1.6.4

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Requiring two items in inventory to shot
« Reply #3 on: 2005-12-08, 09:06:09 AM »
"Require in Inventory" is what I meant.  Wow, I thought the I would have used the correct term in the documentation, but I guess not.

jweldon

  • Visitor
  • *
  • Posts: 16
    • View Profile
    • Email
Re: Requiring two items in inventory to shot
« Reply #4 on: 2005-12-08, 09:20:29 AM »
Awesome!  It worked great!  I changed it and tested it already.
Thanks for your help!

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
Re: Requiring two items in inventory to shot
« Reply #5 on: 2005-12-14, 01:52:59 AM »
From what I can tell, it's impossible or at least really really hard to do a shooting script or anything requiring two or more variables without scripting.  Personally, I would just save yourself the trouble and do a little bit of scripting and use functions that raise special events.  It's really easy and it's a lot easy than having string of special functions that activate each and don't really work anyways.

I don't remember the details as to why exactly you can't check for two variables (been too long), but it's something like this (or at least how I went about trying):
1.  you have a special function that checks for your first variable.
2.  If you have that first variable, then that special activates a series of special functions.
3  The special functions you just activated each check for your own variables.
That would be a good method for checking for two variables but from what I can tell it just doesn't work (I may be just missing something, who knows).  The second set of functions that get activated by the first function just fire off automatically no matter what you have them check for.  I think that's how it was with me, I may be a little off but I'm pretty sure that was the case.

The way I fixed this was to have that original function check for its variable and then you have that function raise an event.  You then make a script that has the same name of that function do whatever you want it to do and it's pretty easy from there.  I don't have my script on me at the moment so I can't tell you the syntax but I can post it later if nobody else posts how to raise an event.  Once you get the hang of it, it's really pretty easy.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Requiring two items in inventory to shot
« Reply #6 on: 2005-12-14, 08:31:16 AM »
The reason this doesn't work is because the checks the engine makes when activating a function only apply in the case where the special function is activated by the player touching it.  So if the first one is activated by the player, and that activates another one automatically, it won't do any checking, it will simply activate it (As you have seen).
Edward Dassmesser