Quick Viewport helpers for upgrading from 3.4.x to 3.5 or higher

Started by Monsieur OUXX, Sun 29/12/2019 20:10:44

Previous topic - Next topic

Monsieur OUXX

Add a module to your game and paste this script into it.
Your game created in 3.4.x should compile in 3.5.x without complaining about the new Viewports system. Please note that you'll have to "replace all" System.ViewportHeight and System.ViewportWidth with System.ViewportHeight() and System.ViewportWidth().

Please note that I did that in exactly 5 minutes and it seemed to work with Tumbleweed (calin leafshade wink wink) but I didn't test thoroughly.
Also, if someone already posted that before then please ignore and assume that their version is better.



Code for the module's header:
Code: ags

import int ViewportHeight(static System);
import int ViewportWidth(static System);
import int ScreenHeight(static System);
import int ScreenWidth(static System);
import int GetViewportX();
import int GetViewportY();
import void SetViewport(int x,  int y);
import void ReleaseViewport();




Code for the module's body:
Code: ags

int ViewportHeight(static System)
{
  return Game.Camera.Height;
}

int ViewportWidth(static System)
{
  return Game.Camera.Width;
}


int ScreenHeight(static System)
{
  return Game.Camera.Height;
}

int ScreenWidth(static System)
{
  return Game.Camera.Width;
}

int GetViewportX()
{
  return Game.Camera.X;
}

int GetViewportY()
{
  return Game.Camera.Y;
}

void SetViewport(int x,  int y)
{
  Game.Camera.SetAt(x,  y);
}

void ReleaseViewport()
{
  Game.Camera.AutoTracking = true;
}



 

Crimson Wizard

There's also a "Script compatibility level" option in General Settings that will return all the old functions back if you set it to previous version.

morph100

OK just picked this back up after 5 years off :-)

I've got this If statement:

  if ((ypos + autoheight + CDG_options.yscreenborder) > System.ViewportHeight(static System)) {
    ypos = System.ViewportHeight - autoheight - CDG_options.yscreenborder; 
  }


with this:

import int ViewportHeight(static System);

and i get:

DialogScript.asc(432): Error (line 432): Parse error in expr near 'static'


can anyone help me, to say im rusty is an understatement

Crimson Wizard

Quote from: morph100 on Today at 13:03:36if ((ypos + autoheight + CDG_options.yscreenborder) > System.ViewportHeight(static System)) {

The expression "System.ViewportHeight(static System)" in this line should be just "System.ViewportHeight()".

The "(static System)" part is used only when declaring an extender function, but not when calling one.
https://adventuregamestudio.github.io/ags-manual/ExtenderFunctions.html#static-extenders

morph100

But then i get

( expected


  if ((ypos + autoheight + CDG_options.yscreenborder) > System.ViewportHeight()) {
    ypos = System.ViewportHeight - autoheight - CDG_options.yscreenborder; 
  }
  else if (ypos < CDG_options.yscreenborder) ypos =  CDG_options.yscreenborder;

Crimson Wizard

Which exactly line do you have this error on? Is it really the exact error message that you are getting? You can copy the error message by selecting it in the output window, right click - copy selected.

Also please clarify:
1. Which version of AGS are you using?
2. Which are the settings "Script API version" and "Script compatibility level" in General Settings?
3. Are you using these helper functions posted above?

SMF spam blocked by CleanTalk