Community

SCI Programming => SCI Syntax Help => Topic started by: stateofpsychosis on November 10, 2014, 10:26:53 AM

Title: How do you make objects Drop to the ego's position
Post by: stateofpsychosis on November 10, 2014, 10:26:53 AM
Hi,

I want to make it so if I say drop a certain object
that it will drop at the ego's position and have the view show up where it's dropped.

I also don't know how to (send to a prop to change it's view loop or cell or any of that so I'm pretty stuck.

thanks!
Title: Re: How do you make objects Drop to the ego's position
Post by: Cloudee1 on November 10, 2014, 12:30:36 PM
It can't be done without some major coding. As in, as far as I know (or know how), it isn't something that is possible out of the box.

I will describe a way to accomplish it as best as I can, but you may also want to take a look at the source code for Manic Mansion as there is a whole lot of this going on in there...

So here goes...
In the Main script you will need to keep track of what room an item has been dropped in. Supposedly this can be done with the inventory items owner variable but I am not quite sure the syntax to make it happen. Instead I went with a bunch of global variables

Code: [Select]
inventory1Room = 0
inventory2Room = 0
inventory3Room = 0

Now, I am assuming that you are also going to want the x and y position remembered as well. This is going to require another group of variables in the main script.

Code: [Select]
inventory1X = 0
inventory1Y = 0
inventory2X = 0
inventory2Y = 0
inventory3X = 0
inventory3Y = 0

Now that should take care of what we need in the main script, remember though, anytime you make a change in the main script you will want to "compile all" otherwise you will get errors when testing your game. You must you must compile all. Assuming you have, we will want to switch gears to the rooms script now. First lets go ahead and create the instances that are needed in the room for the inventory items. For now, leave the x and y positioning off screen but feel free to set the view loop and cel accordingly.

Code: [Select]
(instance inventory1View of Prop(properties x 400 y 400 view 2 loop 0 cel 1))
(instance inventory2View of Prop(properties x 400 y 400 view 2 loop 0 cel 2))
(instance inventory3View of Prop(properties x 400 y 400 view 2 loop 0 cel 3))

and then we will need the bit in the init section of the rooms script which determines whether or not the view should appear on the screen.

Code: [Select]
(if(== inventory1Room scriptNumber)(inventory1View:init()posn(inventory1X inventory1Y)))
(if(== inventory2Room scriptNumber)(inventory2View:init()posn(inventory2X inventory2Y)))
(if(== inventory3Room scriptNumber)(inventory3View:init()posn(inventory3X inventory3Y)))

Ok, so theoretically that will handle the placement of the item in the room. Now we need to actually feed the global variables some values to see if it works. Now I don't usually use the parser so it has been a long time since I have worked with if said statements. But here goes... This should be placed in the handleEvent method of the RoomScript instance

Code: [Select]
(if(Said('drop/item1')) // whatever item1 is of course
  (if(send gEgo:has(1)) // check that ego has the item to begin with
  Print("You drop the item at your feet.") // let them know it's dropped
  = inventory1Room scriptNumber // set the global variable, so it remembers where item 1 was dropped
  = inventory1X (send gEgo:x) // set the global variable, so it remembers the x posn of where it was dropped
  = inventory1Y (+ (send gEgo:y) 3) // set the global variable, so it remembers the y posn of where it was dropped
  (send gEgo:put(1))// get the item out of the users inventory
  (inventory1View:init()posn((send gEgo:x) (+ (send gEgo:y) 3))) // init the item right now
  )
  (else Print("You don't have that to drop."))
) // end said drop item

We are getting close now... all that is left is to pick up the dropped item and reset the global variables back to 0's


Code: [Select]
(if(Said('get/item1')) // whatever item1 is of course
  (if(send gEgo:has(1))Print("You already have that.")) // check that ego hasn't already picked it up
  (else
     (if(== inventory1Room scriptNumber) // make sure it is here to begin with 
     Print("You pick up the item.") // let them know it's picked up
     = inventory1Room 0// reset the global variable
     = inventory1X 0 // reset the global variable
     = inventory1Y 0 // reset the global variable
     (send gEgo:get(1))// get the item in the users inventory
     (inventory1View:posn(400 400)hide()) // get the item view off screen
)
     (else Print("You don't see that here."))
  )
) // end said get item


------------------------------------

Now then, as for your second question... super easy.
assuming that each of your props has it's own instance and then is just being inited. You can change any of the props values anytime. Here is an example that I hope makes it easy to understand

Code: [Select]
(if(Said('open/window'))
 (whatEverInstanceNameIs:view(4)loop(8)cel(3)posn(160 59))
)
(else
  (if(Said('close/window'))
   (whatEverInstanceNameIs:view(7)loop(3)cel(0)posn(132 48))
  )
)
Title: Re: How do you make objects Drop to the ego's position
Post by: Collector on November 10, 2014, 12:46:18 PM
That was more involved than what I was thinking, but I was forgetting to take into account the need of managing it in the globals, which is obvious once you think it through.
Title: Re: How do you make objects Drop to the ego's position
Post by: stateofpsychosis on November 10, 2014, 12:50:15 PM
wow, that's really way tougher than I expected.

I might want to just use fixed positions if I can't get this working easily enough

I'm going to try it though

thanks!

good thing it's only for 2 objects and not every object in the game :P
Title: Re: How do you make objects Drop to the ego's position
Post by: Cloudee1 on November 10, 2014, 12:58:16 PM
Yeah, that is part of what killed my heap in Manic Mansion, the code for the stolen inventory items... looking, talking, getting etc had to be coded into every room and I had 13 or 14 items in the game. So by the time it was all said and done, it was a sizeable chunk of code to be able to click on items that may or may not even be there.

There are a few considerations, but it isn't really a complex bit of coding. Hopefully if you take a moment and look at each bit and can see why it was done you'll see that all of it was necessary and why.
Title: Re: How do you make objects Drop to the ego's position
Post by: stateofpsychosis on November 10, 2014, 01:14:00 PM
hey it worked on the first try :)

nice cloudee1

you're the man!