Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 667 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
variables in while-loop #410642
11/06/12 17:19
11/06/12 17:19

C
chris_oat
Unregistered
chris_oat
Unregistered
C



Hi,

ok here it is:
i have this while-loop inside my player-move-code:
Code:
while(1)
{
abs_movement_x_0 = player.x;
abs_movement_y_0 = player.y;

...code...

c_move(my,vector(player_movevector[0],player_movevector[1],0),nullvector,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE | IGNORE_PUSH);

...code...

abs_movement_x_1 = player.x;
abs_movement_y_1 = player.y;
//Distanz der Vektoren berechnen
abs_movement_x_1 = abs_movement_x_1 - abs_movement_x_0;
abs_movement_y_1 = abs_movement_y_1 - abs_movement_y_0;
abs_movement_res = sqrt(abs_movement_x_1*abs_movement_x_1 + abs_movement_y_1*abs_movement_y_1);
		
wait(1);
}


the code above works. var abs_movement_res gets updated correctly.
But now i changed the c_move into:
Code:
pXent_move (my, vector(player_movevector[0],player_movevector[1],player_movevector[2]), NULL);


after this, the variable stay always the same it doesnt get updated.
Does anyone know why?

Thanks for any input!

Re: variables in while-loop [Re: ] #410647
11/06/12 17:33
11/06/12 17:33
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I am not sure how pXent_move works, esp. when it is executed resp. when the entity gets moved, but it could be that this only happens in physX_run/ at the end of a frame.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: variables in while-loop [Re: Superku] #410649
11/06/12 17:39
11/06/12 17:39

C
chris_oat
Unregistered
chris_oat
Unregistered
C



hmmm, so what could i do about it??
i thought no matter how the entity gets moved, it just checks for the players x, y coordinates every frames. why would C_move be any different then pXent_move, both just move the entity...

Re: variables in while-loop [Re: ] #410652
11/06/12 18:16
11/06/12 18:16
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Hm no, it's not necessary the same as physX is a plug-in that connects physical bodies to Gamestudio's entities. Maybe only the physX object is moved and the entity is placed at its position at the end of the frame. You could try to read the position of the former, not the position of the entity itself.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: variables in while-loop [Re: Superku] #410678
11/07/12 05:35
11/07/12 05:35

C
chris_oat
Unregistered
chris_oat
Unregistered
C



Fixed it!
I believe the c_move was so slow that it actually caused a delay between the variables above and below the command, while the pXent_move was way faster that the variables stays the same and thus didnt get new values.
I now wrote a new void function where I wrote the variables and just put a Wait(1); instead of the c_move laugh
It may not be the best solution, but it does work!
Code:
while(1)
{
abs_movement_x_0 = player.x;
abs_movement_y_0 = player.y;

wait(1);

abs_movement_x_1 = player.x;
abs_movement_y_1 = player.y;
//Distanz der Vektoren berechnen
abs_movement_x_1 = abs_movement_x_1 - abs_movement_x_0;
abs_movement_y_1 = abs_movement_y_1 - abs_movement_y_0;
abs_movement_res = sqrt(abs_movement_x_1*abs_movement_x_1 + abs_movement_y_1*abs_movement_y_1);
		
wait(1);
}


Re: variables in while-loop [Re: ] #410679
11/07/12 06:26
11/07/12 06:26
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Well, now it does exactly what you thought would be the problem...
Also, this is not how Lite-C works, but congrats on fixing the symptoms.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: variables in while-loop [Re: WretchedSid] #410687
11/07/12 09:00
11/07/12 09:00

C
chris_oat
Unregistered
chris_oat
Unregistered
C



yes, unfortunally thats the only thing i was able to at the moment, fixing the symptoms, but not the cause...
im not that good in coding, and i never will be but if you can give me a better solution and explane it to me how it works iam very thanksful laugh

Re: variables in while-loop [Re: ] #410689
11/07/12 09:45
11/07/12 09:45
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
I think you can achieve the same thing using

  • init old and new position variables
  • set new position
  • calculate delta
  • save current position in old_pos variable


Code:
function main()
{
   var x = 0, y = 0;
   
   // New position
   var abs_movement_x0 = 1;
   var abs_movement_y0 = 1;
   
   // Last position
   var abs_movement_x1 = 1;
   var abs_movement_y1 = 1;
   
   while(1)
   {
      // Set new position
      abs_movement_x0 = x;  
      abs_movement_y0 = y;
      
      ///pXent_move()...............
      
      // Dist (delta = new - old)
      var dx = abs_movement_x0 - abs_movement_x1;
      var dy = abs_movement_y0 - abs_movement_y1;
      
      var length = sqrt(pow(dx, 2) + pow(dy, 2));
      
      // Save Current position for next frame
      abs_movement_x1 = abs_movement_x0;
      abs_movement_y1 = abs_movement_y0;
      
      DEBUG_VAR(length, 10);
      
      // Simulate PhysX update
      var speed = 5;
      x += speed * time_step;
      y += speed * time_step;
      
      wait(1);
   }
}


Last edited by 3dgs_snake; 11/07/12 09:45.

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1