Author Topic: [solved] get current graphic from player  (Read 281 times)

[solved] get current graphic from player
« on: 13 Apr 2018, 00:37 »
Hello,

I need to get the current graphic from the player, I need to do this every instant, I am using this information to draw things on a surface, so at instant t=7 I need the player frame for instant t=7, and not t=6.

I decided to use the following:

Code: Adventure Game Studio
  1. int getPlayerGraphic(){
  2.   ViewFrame * ViewFrame_Player;
  3.   ViewFrame_Player = Game.GetViewFrame(player.View,  player.Loop, player.Frame);
  4.   return  ViewFrame_Player.Graphic;
  5. }
  6.  

but apparently, this gets in the current instant, the graphic that was on screen on the previous instant, so using this information gets a slightly delay.

So I evolved to do the following thing:

Code: Adventure Game Studio
  1. int i_view;
  2. int i_loop;
  3. ViewFrame * ViewFrame_Player;
  4.  
  5. function repeatedly_execute_always(){
  6.   i_view = player.View;
  7.   i_loop = player.Loop;
  8. }
  9.  
  10. function late_repeatedly_execute_always(){
  11.   if(IsGamePaused() == 1  || !System.HasInputFocus){
  12.     return;  
  13.   }
  14.  
  15.   ViewFrame_Player = Game.GetViewFrame(i_view,  i_loop, player.Frame);
  16. }
  17.  
  18. static int PlayerViewframe::getGraphic(){
  19.   return  ViewFrame_Player.Graphic;
  20. }
  21.  

which sometimes works, but in some rare occasions, crashes my software, because player.Frame sometimes is updated and i_view and i_loop isn't, and my loop for down and up have different frame count than left and right. And sometimes, it doesn't update correctly.

So is there a right way of getting the current graphic the player has ?
« Last Edit: 15 Apr 2018, 18:22 by eri0o »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: get current graphic from player
« Reply #1 on: 13 Apr 2018, 01:29 »
So is there a right way of getting the current graphic the player has ?

Maybe this is nitpicking, but I think the question is wrong.
Your very first code example IS the right way of getting the current graphic.
The issue is that you are using that information when it is no longer relevant.

The game loop in AGS goes as this:
- repeatedly_execute
- repeatedly_execute_always (or vice versa, idk)
- game updates its state (animations etc)
- late_repeatedly_execute_always
- rendering

So, we may suppose that you'd need to both query the view, loop, frame and graphic AND set your debug "thing" to draw itself according to that graphic - all in the late_repeatedly_execute_always.
« Last Edit: 13 Apr 2018, 01:33 by Crimson Wizard »

Re: get current graphic from player
« Reply #2 on: 13 Apr 2018, 02:43 »
CW you are right! I didn't knew I could just use late_repeatedly_execute_always under a RoomN.asc, but apparently I can!!! I also now don't understand the difference between Room_RepExe and repeatedly_execute.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: get current graphic from player
« Reply #3 on: 13 Apr 2018, 02:56 »
Do you mean it got solved? I did not test this myself.

I also now don't understand the difference between Room_RepExe and repeatedly_execute.

They are the same thing. One of the AGS design quirks, repeatedly_execute is automatically called in all script modules except rooms, and in rooms you must connect to the event system. But _always functions are called like in normal modules.
And room function does not have to be called Room_RepExec, you may also call it repeatedly_execute, if you register it in the events pane with correct name.
« Last Edit: 13 Apr 2018, 02:59 by Crimson Wizard »

Re: get current graphic from player
« Reply #4 on: 14 Apr 2018, 14:16 »
Yes, it got solved! I think each .asc listed under script (not rooms) repeatedly_execute, are called from top to bottom and me not paying attention lead to ultimate confusion!
« Last Edit: 14 Apr 2018, 14:19 by eri0o »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: get current graphic from player
« Reply #5 on: 14 Apr 2018, 14:45 »
Yes, it got solved! I think each .asc listed under script (not rooms) repeatedly_execute, are called from top to bottom and me not paying attention lead to ultimate confusion!

Yes ofcourse, all callbacks in modules are called from top to bottom in AGS (in the order of module dependency), this is also how ClaimEvent function works: it stops event propagation in certain module, allowing you do a trick when particular script disables all others for a while.
« Last Edit: 14 Apr 2018, 15:33 by Crimson Wizard »