Two different solutions, one slow the other fast why?

Stuck? This is the place to go to get and give help.

Two different solutions, one slow the other fast why?

Postby lucky » February 1st, 2011, 12:54 am

I have started to develop the demo game X-asteroids as a project to learn more about ds game maker.

I have a couple of "enemy" objects on the screen and i want to control how the objects are moving.
In the demo game there was a control object named "Player" and in that object the code for moving the enemys was executed. I made a enemy_control object and I wanted to use the velocity [VX] to control the objects movement instead of the solution in the original demo. Unfortunately this seemed to be a very slow solution.
I then put the code directly in the enemy object and the game was executing fast and smooth.

my first attempt
if one of the instances of enemy is out of screen change the direction of all of the instances
global.jpg


the good solution ( I put almost the same code directly in the enemy object)
if this instance is out of screen then change the direction of all of us
enemy.jpg


why is the second solution so much faster i have preferred the first one??

/lucky
lucky
 
Posts: 51
Joined: January 6th, 2011, 5:10 pm
Location: Sweden

Re: Two different solutions, one slow the other fast why?

Postby Thungbard » February 1st, 2011, 1:23 am

It's difficult to know what you mean by fast and slow, when there's no demo of either. It's also difficult to tell why one would be fast or slow when all we can see of it is 2 nearly identical screenshots of completely equivalent action code.
Thungbard
 
Posts: 301
Joined: December 30th, 2010, 8:09 pm
Location: Canada

Re: Two different solutions, one slow the other fast why?

Postby lucky » February 1st, 2011, 1:43 am

sorry!!
here you have the source fore the two examples
theGameD1.dsgm
(681 KiB) Downloaded 18 times

theGameD1.dsgm
(681 KiB) Downloaded 18 times


/lucky
Attachments
theGameD2.dsgm
(681.01 KiB) Downloaded 20 times
lucky
 
Posts: 51
Joined: January 6th, 2011, 5:10 pm
Location: Sweden

Re: Two different solutions, one slow the other fast why?

Postby Thungbard » February 1st, 2011, 4:00 am

Not only is the first way slower, it also doesn't work, as in the enemies don't turn around when one of them hits the edge of the screen, they just keep going off the screen. So your enemy controller object has bigger problems than the speed.

Also in the version that works, if you just sit and wait till the Right Enemies come down to the bottom screen their initial speed is in the wrong direction so they just pulsate instead of moving the whole length of the screen because the top row hits the right side of the top screen as the bottom row keeps hitting the left side of the bottom screen.

The strange thing is that both versions, the Left Enemies have the exact same code yet they also move slower in one of the versions not just the Right Enemies that have different code.
Thungbard
 
Posts: 301
Joined: December 30th, 2010, 8:09 pm
Location: Canada

Re: Two different solutions, one slow the other fast why?

Postby lucky » February 1st, 2011, 9:05 am

Ok Thungbard
Now I have cooked it down to a very simple example based on the tutorial files 6. velocity.

have a look here

Velocity1.dsgm
(2.27 KiB) Downloaded 19 times

Velocity2.dsgm
(2.3 KiB) Downloaded 16 times



why is number one working but not number two

getting a answer to this would realey make me a better ds game programmer
lucky
 
Posts: 51
Joined: January 6th, 2011, 5:10 pm
Location: Sweden

Re: Two different solutions, one slow the other fast why?

Postby crislovestefy_4e » February 1st, 2011, 11:03 am

Ahahaha the tre balls go out from bottom screen :D boh
crislovestefy_4e
 
Posts: 17
Joined: January 28th, 2011, 8:15 am

Re: Two different solutions, one slow the other fast why?

Postby crislovestefy_4e » February 1st, 2011, 11:04 am

Follow the Bouncing Balls examples :D this is very instructive :D
crislovestefy_4e
 
Posts: 17
Joined: January 28th, 2011, 8:15 am

Re: Two different solutions, one slow the other fast why?

Postby Thungbard » February 1st, 2011, 1:17 pm

lucky wrote:Ok Thungbard


The problem with the second is it doesn't execute the code the way it appears it should. I went and simplified it even further for you.
error.png


Here's the things to know:

- All Balls are initialized to move Right
- Balls instances are 0,1,2
- Controller instance is 3
- The if Statement in the controller object is set to "all instances of Ball"
- if you change the If statement to compare the ID to 3 which is the controlloers ID the balls now move Left
- if you have the IF statement compare to any of the ID's of the actual balls, the balls never turn around and continue right

My analysis is that it's because the way the code is executing isn't:
Loop through all Balls if any of them are off the screen perform what's inside the start and end block

It checks the condition of the If statement without checking it for each ball, it checks it for the controller even if the radio box is checked as "Instances of: Ball"
Thungbard
 
Posts: 301
Joined: December 30th, 2010, 8:09 pm
Location: Canada

Re: Two different solutions, one slow the other fast why?

Postby lucky » February 1st, 2011, 9:14 pm

Okej I understand
Thank you for your excellent explanation.
Would you agree to say that we have found a bug?
James?
lucky
 
Posts: 51
Joined: January 6th, 2011, 5:10 pm
Location: Sweden

Re: Two different solutions, one slow the other fast why?

Postby Thungbard » February 2nd, 2011, 12:08 am

I would agree that it doesn't work the way it should, but I also think an If statement that's set to all instances of an object is kind of complex and would be a lot of work to make properly, so I was a bit surprised that the option was even available.
Thungbard
 
Posts: 301
Joined: December 30th, 2010, 8:09 pm
Location: Canada

Re: Two different solutions, one slow the other fast why?

Postby James » February 2nd, 2011, 1:20 am

This is quite a confusing topic. The C code for applying an action to instances of an object is not pretty by any stretch of the imagination. Take a look. It'll let you know if there's a bug.

It seems in this case though that an awkward situation has arisen for which there is a solution - awkward situations with solutions aren't worthy of so much attention as other critical things.

Regardless, I want to fix a bug, but as always, give me certain and full information.
James
Site Admin
 
Posts: 810
Joined: December 30th, 2010, 3:23 am
Location: Lancaster University, England

Re: Two different solutions, one slow the other fast why?

Postby Thungbard » February 2nd, 2011, 3:59 am

James wrote:Take a look. It'll let you know if there's a bug.

I have no idea where the C code for the instancing is, so I have no way of looking for the bug but in a nutshell:

Normal Actions, for example: Set Variable [X] = 0 if you select to Apply to Instances of an object, it will move all instances of that object to the left side of the screen

Conditional Actions, on the other hand, whether you select Applies To This or Applies To Instances of an Object, the If statement is executed the same.

Here's the absolute simplest example I could think of:

- 1 Room
- 2 Objects
- First object is a Banana with ID of 0
- Second object is a Searcher with ID of 1

The Searcher checks if [Me]==1 for instances of Banana's and outputs yes or no based on the result.

It should output 'No' because the ID of the only instance of Banana is 0, but it outputs 'Yes' because it's actually checking if the Searcher's ID is 1, even though the Applies To Instances of Banana is selected.
Instancing1.dsgm
(977 Bytes) Downloaded 17 times
Thungbard
 
Posts: 301
Joined: December 30th, 2010, 8:09 pm
Location: Canada


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron