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:
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:
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;
}
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.
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
Quote from: morph100 on Thu 14/08/2025 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
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;
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?
The manual lists it as:
readonly static int System.ViewportHeight;
i.e. it's not even a function; it's just an int.
Since 3.5.0 it's also obsolete; the proper way is to simply use Screen.Height:
if (ypos + autoheight + CDG_options.yscreenborder > Screen.Height) {
ypos = Screen.Height - autoheight - CDG_options.yscreenborder;
}
Quote from: Khris on Sat 16/08/2025 11:22:27The manual lists it as:
readonly static int System.ViewportHeight;
i.e. it's not even a function; it's just an int.
Khris, this thread suggests a "compatibility" script module, where these attributes are turned into extender functions (see the first post). The extender attributes are not supported in 3.* versions, that's why the OP made them functions, I think.
Right; I should've scrolled up first :-D
But do we know that
@morph100 is actually using the module/code? If it's just a few lines that have to be amended even with the module, using it seems kind of pointless.
I got the error on the first line of the IF statement.
Using latest version
Script settings all set to latest version.
Do I just need to scrap this bit and re-do it using the latest methods? What's a good resource to revise and look at.
I'm on holiday at the minute, back in a week so can read up but can't test anything unfortunately
Quote from: morph100 on Mon 18/08/2025 11:01:17I got the error on the first line of the IF statement.
Are you using the helper functions posted in the beginning of this thread, or no?
This forum thread is dedicated to having these functions in your script, as a replacement to the old engine functions. If you do not, then of course the suggested code won't work.
The three common options that you have:
1. Change "Script compatibility level" to the older version, as explained here:
https://adventuregamestudio.github.io/ags-manual/GeneralSettings.html#backwards-compatibility
This will enable old functions back.
or
2. Replace the use of the old functions with the new ones. There's a table of replacement here:
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html
or
3. Actually copy the helper functions posted in this forum thread (first post) to your game. Better make a separate script module for them and have that module on the top of your script list (so that other scripts could use them). Then you still have to adjust your scripts, adding "()" function call for things like "System.ViewportHeight" and similar.
Personally, I can't recommend the 3rd option, because from the looks of it these helper functions are not written entirely correctly, they may fail in certain cases.
The camera script API in the manual gives some explanation on how they work
https://adventuregamestudio.github.io/ags-manual/Camera.html
You can imagine something like, your rooms can be "captured" with a camera and they are then be projected to a viewport. You can only see viewports on the screen.
By default AGS sets a camera to the size of the game resolution and "attaches" it to a viewport that also has the same size.
Quote from: Crimson Wizard on Mon 18/08/2025 15:33:28Quote from: morph100 on Mon 18/08/2025 11:01:17I got the error on the first line of the IF statement.
Are you using the helper functions posted in the beginning of this thread, or no?
This forum thread is dedicated to having these functions in your script, as a replacement to the old engine functions. If you do not, then of course the suggested code won't work.
The three common options that you have:
1. Change "Script compatibility level" to the older version, as explained here:
https://adventuregamestudio.github.io/ags-manual/GeneralSettings.html#backwards-compatibility
This will enable old functions back.
or
2. Replace the use of the old functions with the new ones. There's a table of replacement here:
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html
or
3. Actually copy the helper functions posted in this forum thread (first post) to your game. Better make a separate script module for them and have that module on the top of your script list (so that other scripts could use them). Then you still have to adjust your scripts, adding "()" function call for things like "System.ViewportHeight" and similar.
Personally, I can't recommend the 3rd option, because from the looks of it these helper functions are not written entirely correctly, they may fail in certain cases.
Thanks that's really useful I think I'll use option 2 to rewrite my scripts in the new format. I'd rather bring it up to date than just run in an old compatible mode