Jump to content


Photo

help with object replacement actions


  • Please log in to reply
19 replies to this topic

#1 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 29 January 2012 - 11:21 PM

In a maze game I am creating, I am trying to make my main character (object) not able to travel backwards (on the path it has already travelled). I have tried a collision event to replace (object change instance) the gathered object (diamond) with a solid object (rock) but the rock is placed too quickly and i cant find a way to delay the replacement. Any ideas on how to do this? Or perhaps there is a different approach to not being able to travel a path already travelled? Thank you in advance for assistance!!!
  • 0

#2 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 30 January 2012 - 12:57 AM

delay the replacement.


You can use an 'Alarm Event'. This is like an alarm - you set the time, and when that time reaches 0, it executes everything inside the event just once. For example:

(Are you using Drag and Drop - My assumption is that you are)

in Alarm Event 0:
object change instance

in Collision Event (with player - or whatever)
Set Variable
Variable: alarm[0]
Value: 20  <- this value is the length of the delay

Alternatively: Couldn't you just move the rock behind the player??
  • 0

#3 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 30 January 2012 - 01:52 AM

Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.
  • 0

#4 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 30 January 2012 - 02:41 AM

Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.


I think the most problem-free solution is the second idea. What movement system are you using? I am going to assume you are using a grid/tile system. How big are the squares on your grid? I'll assume they are 32x32 pixels (if your grid measurements are different to this, don't forget to change the values (32's) in my example code). You can try this:

Collision Event (with Player - or what ever)
(DragAndDrop Action) - Set Variable
Variable: x
Value: floor((other.x+(other.xprevious-other.x)*3)/32)

(DragAndDrop Action) - Set Variable
Variable: y
Value: floor((other.y+(other.yprevious-other.y)*3)/32)

(DragAndDrop Action) - Object Change Instance
  • 0

#5 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 30 January 2012 - 05:24 AM


Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.


I think the most problem-free solution is the second idea. What movement system are you using? I am going to assume you are using a grid/tile system. How big are the squares on your grid? I'll assume they are 32x32 pixels (if your grid measurements are different to this, don't forget to change the values (32's) in my example code). You can try this:

Collision Event (with Player - or what ever)
(DragAndDrop Action) - Set Variable
Variable: x
Value: floor((other.x+(other.xprevious-other.x)*3)/32)

(DragAndDrop Action) - Set Variable
Variable: y
Value: floor((other.y+(other.yprevious-other.y)*3)/32)

(DragAndDrop Action) - Object Change Instance



Your assumptions are correct. Thank you for your instructions. I revised the diamond object collision event (with the player) to perform the following actions:

Set the score relatitive to 200.
Play sound of cash register.
Set variable x (Applies to: self, Variable: x, Value: floor((other.x+(other.xprevious-other.x)*3/32), Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: floor((other.y+(other.yprevious-other.y)*3/32), Relative: checked).
Change instance (Applies to: self, Change into: object_rock, Perform events: yes).

This is what's happening:
1. The diamond object is changing into the rock object (instantly) as player is passing over diamond. This is not desireable since the rock plays a "wrong way" sound when touched. I think this is where an alarm needs to be set up to delay the object swap but im not sure exactly where to place it or input settings for alarm relative to the other actions within the above described event.
2. When the rock are inserted, they are progressively being placed slightly lower and to the right each time.

I look forward to your suggestions on how to slove these two items.
  • 0

#6 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 30 January 2012 - 05:40 AM



Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.


I think the most problem-free solution is the second idea. What movement system are you using? I am going to assume you are using a grid/tile system. How big are the squares on your grid? I'll assume they are 32x32 pixels (if your grid measurements are different to this, don't forget to change the values (32's) in my example code). You can try this:

Collision Event (with Player - or what ever)
(DragAndDrop Action) - Set Variable
Variable: x
Value: floor((other.x+(other.xprevious-other.x)*3)/32)

(DragAndDrop Action) - Set Variable
Variable: y
Value: floor((other.y+(other.yprevious-other.y)*3)/32)

(DragAndDrop Action) - Object Change Instance



Your assumptions are correct. Thank you for your instructions. I revised the diamond object collision event (with the player) to perform the following actions:

Set the score relatitive to 200.
Play sound of cash register.
Set variable x (Applies to: self, Variable: x, Value: floor((other.x+(other.xprevious-other.x)*3/32), Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: floor((other.y+(other.yprevious-other.y)*3/32), Relative: checked).
Change instance (Applies to: self, Change into: object_rock, Perform events: yes).

This is what's happening:
1. The diamond object is changing into the rock object (instantly) as player is passing over diamond. This is not desireable since the rock plays a "wrong way" sound when touched. I think this is where an alarm needs to be set up to delay the object swap but im not sure exactly where to place it or input settings for alarm relative to the other actions within the above described event.
2. When the rock are inserted, they are progressively being placed slightly lower and to the right each time.

I look forward to your suggestions on how to slove these two items.


try changing the 'set variable' actions like this:

Set variable x (Applies to: self, Variable: x, Value: (sign(other.xprevious-other.x))*65, Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: (sign(other.yprevious-other.y))*65, Relative: checked).

What this should do is place the rock directly behind the player, plus an extra pixel, so that they don't make contact (so that sound doesn't play).
  • 0

#7 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 30 January 2012 - 08:19 AM




Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.


I think the most problem-free solution is the second idea. What movement system are you using? I am going to assume you are using a grid/tile system. How big are the squares on your grid? I'll assume they are 32x32 pixels (if your grid measurements are different to this, don't forget to change the values (32's) in my example code). You can try this:

Collision Event (with Player - or what ever)
(DragAndDrop Action) - Set Variable
Variable: x
Value: floor((other.x+(other.xprevious-other.x)*3)/32)

(DragAndDrop Action) - Set Variable
Variable: y
Value: floor((other.y+(other.yprevious-other.y)*3)/32)

(DragAndDrop Action) - Object Change Instance



Your assumptions are correct. Thank you for your instructions. I revised the diamond object collision event (with the player) to perform the following actions:

Set the score relatitive to 200.
Play sound of cash register.
Set variable x (Applies to: self, Variable: x, Value: floor((other.x+(other.xprevious-other.x)*3/32), Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: floor((other.y+(other.yprevious-other.y)*3/32), Relative: checked).
Change instance (Applies to: self, Change into: object_rock, Perform events: yes).

This is what's happening:
1. The diamond object is changing into the rock object (instantly) as player is passing over diamond. This is not desireable since the rock plays a "wrong way" sound when touched. I think this is where an alarm needs to be set up to delay the object swap but im not sure exactly where to place it or input settings for alarm relative to the other actions within the above described event.
2. When the rock are inserted, they are progressively being placed slightly lower and to the right each time.

I look forward to your suggestions on how to slove these two items.


try changing the 'set variable' actions like this:

Set variable x (Applies to: self, Variable: x, Value: (sign(other.xprevious-other.x))*65, Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: (sign(other.yprevious-other.y))*65, Relative: checked).

What this should do is place the rock directly behind the player, plus an extra pixel, so that they don't make contact (so that sound doesn't play).



I changed it as you suggested and it works perfectly!! I will test it for round twotomorrow with our blind volunteer. Based upon her comments from the initial test, these improvements are exactly what she was requesting. I'm very greatful for your help! Couldnt have done it without you!
  • 0

#8 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 30 January 2012 - 05:48 PM





Thank you for your response. I have tried placing an alarm, but am probably placing it incorrectly. Does it have to be entered as a second event (alarm) after the player collides with the diamond or do you add the alarm within the first collision event after the sound of colliding with the diamond?

It may be easier to accomplish your second idea. Can you elaborate on how to place an object (rock) in each position behind the player so it doesnt contact the player when placed? It should only respond when the player tries to go backwards.

By the way, this is a science project designing a viseo game for the blind, so sound is the key ingredient here for clues on what to do next. I have a trail of diamonds along the correct path within the maze, but once the diamonds are collected, i need something placed behind the player to prevent them from going backards. Right now, after the diamonds are collected, if they go backwards, there is no sound to give the player information that they are going the wrong way.

Let me know what you think.


I think the most problem-free solution is the second idea. What movement system are you using? I am going to assume you are using a grid/tile system. How big are the squares on your grid? I'll assume they are 32x32 pixels (if your grid measurements are different to this, don't forget to change the values (32's) in my example code). You can try this:

Collision Event (with Player - or what ever)
(DragAndDrop Action) - Set Variable
Variable: x
Value: floor((other.x+(other.xprevious-other.x)*3)/32)

(DragAndDrop Action) - Set Variable
Variable: y
Value: floor((other.y+(other.yprevious-other.y)*3)/32)

(DragAndDrop Action) - Object Change Instance



Your assumptions are correct. Thank you for your instructions. I revised the diamond object collision event (with the player) to perform the following actions:

Set the score relatitive to 200.
Play sound of cash register.
Set variable x (Applies to: self, Variable: x, Value: floor((other.x+(other.xprevious-other.x)*3/32), Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: floor((other.y+(other.yprevious-other.y)*3/32), Relative: checked).
Change instance (Applies to: self, Change into: object_rock, Perform events: yes).

This is what's happening:
1. The diamond object is changing into the rock object (instantly) as player is passing over diamond. This is not desireable since the rock plays a "wrong way" sound when touched. I think this is where an alarm needs to be set up to delay the object swap but im not sure exactly where to place it or input settings for alarm relative to the other actions within the above described event.
2. When the rock are inserted, they are progressively being placed slightly lower and to the right each time.

I look forward to your suggestions on how to slove these two items.


try changing the 'set variable' actions like this:

Set variable x (Applies to: self, Variable: x, Value: (sign(other.xprevious-other.x))*65, Relative: checked).
Set variable y (Applies to: self, Variable: y, Value: (sign(other.yprevious-other.y))*65, Relative: checked).

What this should do is place the rock directly behind the player, plus an extra pixel, so that they don't make contact (so that sound doesn't play).



I changed it as you suggested and it works perfectly!! I will test it for round two tomorrow with our blind volunteer. Based upon her comments from the initial test, these improvements are exactly what she was requesting. I'm very greatful for your help! Couldnt have done it without you!


I found one more problem that may make the game confsusing for a blind player. The rock, which is dropped behind the player to block the path that has already been travelled, is allowing the player to move over it which is not desired. When i change the rock object to solid (checking the box), the game freezes when the player makes contact with the rock. I have copied the same collision settings for the wall and used them for the rock, but the player still freezes after the collision. Any suggestions for this fix?

Thank you in advance!!
  • 0

#9 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 01:11 AM

I found one more problem that may make the game confsusing for a blind player. The rock, which is dropped behind the player to block the path that has already been travelled, is allowing the player to move over it which is not desired. When i change the rock object to solid (checking the box), the game freezes when the player makes contact with the rock. I have copied the same collision settings for the wall and used them for the rock, but the player still freezes after the collision. Any suggestions for this fix?

Thank you in advance!!


I'm not sure whether the game is freezing or the object is just getting stuck. Try this code - in the collision event of your player object:

Set Variable:
Variable: x
Value: xprevious
Relative: Unchecked

Set Variable:
Variable: y
Value: yprevious
Relative: Unchecked
  • 0

#10 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 02:08 AM

I tried it and when the player object makes contact with the rock it plays the sound once and gets stuck. I dont think the game is freezing. This is the drop and drag info for my player object;

Under player object properties, i have two collision events with objects wall and rock, and 5 keyboard events, (no key) (up) (down) (left) (right).

The first collision event with wall has the following actions: start moving in a direction. (the player does not get stuck and keeps moving).

The second colision event with rock has the following actions: Start moving in a direction. Set Variable to: x. Set value to: xprevious. Set Variable to: y. Set value to: yprevious. Relative: unchecked.

Let me know what you suggest. Thanks!
  • 0

#11 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 02:24 AM

Hmm... I'm not really sure what the problem is. Try removing the "Start Moving in a Direction" action in the second collision event, though I don't think that that will make a difference. So if that doesn't work try changing:

set x to (xprevious-x)*2, relative: checked
set y to (yprevious-y)*2, relative: checked

If that doesn't work, keep increasing the multiplier (the '2') by one.

Edit: changed some values!!

Edited by rude guss, 31 January 2012 - 02:26 AM.

  • 0

#12 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 03:19 AM

I tried removing the SMIAD, and the sound repeated and player object got stuck.

Then i tried the variables as you suggested up to a multiplier of 6 and it stil got stuck but it moved the player object further and further away from the rock as the multiplier increased.

So, i changed some settings in the rock object (unchecked solid), and left the player object variables as you have them above and keeping the SMAID, and it works moving left and right (the direction you start with)!! Do you know how to make it work in the up and down directions?

Thank you!
  • 0

#13 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 03:56 AM

I forgot to mention that when moving up and down, the player object gets stuck after making contact with the rock object and the sound plays once. Hope this helps.
  • 0

#14 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 04:39 AM

I have no idea as to what is going wrong - What code do you have in your key down events?, I'm guessing just the 'Start Moving in a Direction' actions? If so I am totally stumped.
  • 0

#15 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 05:53 AM

The key down events (no key) (left) (up) (right) (down) have 2 actions: First, If instance is aligned with grid, Applies to: self, Snap hor: 32, Snap vert: 32, Not: not checked. Second, Start moving in a direction, Applies to: self, direction corresponds with event, Speed: 4, Relative: not checked.

Does this help?
  • 0

#16 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 06:00 AM

The key down events (no key) (left) (up) (right) (down) have 2 actions: First, If instance is aligned with grid, Applies to: self, Snap hor: 32, Snap vert: 32, Not: not checked. Second, Start moving in a direction, Applies to: self, direction corresponds with event, Speed: 4, Relative: not checked.

Does this help?


Have you tried removing the 'If instance is aligned with grid' action for all of them?
  • 0

#17 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 06:21 AM

i will give that a try. Here is something i did try which is interesting. I went back to the two original set variables (Xprevious) and (yprevious) and it allowed me to hit the rock in the up and down directions but not in the left and right directions. Then i tried adding the set variables (xprevious-x)*2, relative: checked and (yprevious-y)*2, relative: checked. With the four variables, it will only let me move up and downafter touching a rock, not left and right after touching a rock.

Is there some way that these variables can be combined to allow movement in all 4 directions/
  • 0

#18 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 06:33 AM

Is there some way that these variables can be combined to allow movement in all 4 directions/


They should already work for all 4 directions. If you want to combine then, know that: x = left/right and y = up/down, so you could try:
x = (xprevious-x)*2, relative
y = yprevious, NOT relative

Edited by rude guss, 31 January 2012 - 06:34 AM.

  • 0

#19 dinov

dinov

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 31 January 2012 - 06:41 AM

That's it!!!!!! It works!!!!! Who would have thought? Thank you for your help with this!!!!
  • 0

#20 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 31 January 2012 - 07:40 AM

No worries, I'm glad it worked, as I close to giving up.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users