AGS 4.0 - Alpha 21 for public test

Started by Crimson Wizard, Thu 01/06/2023 14:00:59

Previous topic - Next topic

arj0n

Great, thank you for the quick repley.

Baguettator

Hi !

I'm trying the new multidimmensionnal arrays system, but I encounter an error when building the game.

Here how I proceeded :

.asc script :
int ressource[TOTAL_RESSOURCES, TOTAL_CATEGORIES_RESSOURCES];
[...]
export ressource;

.ash script :
import int ressource[TOTAL_RESSOURCES, TOTAL_CATEGORIES_RESSOURCES];

It's telling "expecting ]" for the line in ash script.

Any idea ?

Crimson Wizard

Quote from: Baguettator on Tue 08/04/2025 06:21:38Hi !

I'm trying the new multidimmensionnal arrays system, but I encounter an error when building the game.

Please double check that you are using the new script compiler, it's selected in General Settings -> Compiler -> Script compiler.

Baguettator

Oh, thanks, I didn't enable it, I thought it was enabled by default !

I got an error when v4 compiler is activated, and I don't understand what it means :

"Struct_Personnage.ash(97): Return type of 'Personnage::set_Mort' is declared as 'bool' here, as 'void' elsewhere. See line 85"

Here is a part of my script (inside the struct "Personnage"), I indicated the lines mentioned in the error message :

Code: ags
import attribute int Blessure, Maladie, Zombivant, Infecte; // L'usage de ces variables est protégé par la struct
  protected int blessure, maladie, zombivant, infecte;
  import attribute bool Mort; // => THIS IS LINE 85
  protected bool mort;
  // les fonctions suivantes sont internes à la struct, elles ne peuvent pas être appeler directement
  import int get_Blessure(); // $AUTOCOMPLETESTATICONLY$
  import void set_Blessure(int _blessure); // $AUTOCOMPLETESTATICONLY$
  import int get_Maladie(); // $AUTOCOMPLETESTATICONLY$
  import void set_Maladie(int _maladie); // $AUTOCOMPLETESTATICONLY$
  import int get_Infecte(); // $AUTOCOMPLETESTATICONLY$
  import void set_Infecte(int _infecte); // $AUTOCOMPLETESTATICONLY$
  import int get_Zombivant(); // $AUTOCOMPLETESTATICONLY$
  import void set_Zombivant(int _zombivant); // $AUTOCOMPLETESTATICONLY$
  import bool get_Mort(); // $AUTOCOMPLETESTATICONLY$
  import bool set_Mort(); // $AUTOCOMPLETESTATICONLY$ => THIS IS LINE 97

And in the .asc script file, the function is declarated like this (it's empty because I don't want anything able to modify this attribute directly) :
Code: ags
bool Personnage::set_Mort()
{
}

I have no problem with v3 compiler. Is it a bug ?

Crimson Wizard

#324
Quote from: Baguettator on Tue 08/04/2025 16:19:05I have no problem with v3 compiler. Is it a bug ?

v3 compiler lets numerous syntax mistakes pass where it should report error. v4 compiler is more strict.

set_ functions of attributes must be "void", because they set and not return. You have other set_ functions as void above, except set_Mort.

Also, you do not need to declare get_ and set_ functions in the struct, attribute declaration is enough.

Baguettator

Quote from: Crimson Wizard on Tue 08/04/2025 16:38:27
Quote from: Baguettator on Tue 08/04/2025 16:19:05I have no problem with v3 compiler. Is it a bug ?

v3 compiler lets numerous syntax mistakes pass where it should report error. v4 compiler is more strict.

set_ functions of attributes must be "void", because they set and not return. You have other set_ functions as void above, except set_Mort.

Also, you do not need to declare get_ and set_ functions in the struct, attribute declaration is enough.

Thanks for helping !

Is it "I don't need" or "I must not" declare get_ and set_functions in the struct ? Because the compiler indicates errors, I had to remove them from the struct in the .ash file.

Crimson Wizard

#326
Quote from: Baguettator on Tue 08/04/2025 20:18:51Is it "I don't need" or "I must not" declare get_ and set_functions in the struct ?

You "don't need", but may.

Note that "set_" functions must have a "new value" as an argument, otherwise they won't compile properly. I.e.
Code: ags
import void set_Mort(int new_mort);

But I missed what you say about "don't want anything able to modify this attribute directly". In such case you should declare your attribute as "readonly", and "set" function should not be present at all.

Code: ags
import readonly attribute bool Mort;

Snarky

Quote from: Baguettator on Tue 08/04/2025 20:18:51Is it "I don't need" or "I must not" declare get_ and set_functions in the struct ?

You can, but you shouldn't. The effect of declaring them as imports is that they get exposed outside of the module, as part of the API of the struct. In other words, it means that other code can call them directly as functions, instead of just using the attribute (which calls them indirectly).

Typically you don't want that, and since you are annotating them with $AUTOCOMPLETESTATICONLY$ (which is wrong, since the functions are not static; if you simply want to prevent autocomplete from listing them, it should be $AUTOCOMPLETEIGNORE$), I assume you don't. So just take them out.

Baguettator

Thanks for helping, I fixed my code :)

I encounter a problem, it seems a bug from the v4 compiler.

Here's my code:

Code: ags
int ressource[TOTAL_RESSOURCES, TOTAL_CATEGORIES_RESSOURCES];
[...]
Ressource1[0].Text=String.Format("%d", ressource[nourriture][colo]); // This is line 1171

And the compiler displays an error :
Struct_Events_Colonie.asc(1171): An array index cannot follow an expression of type 'int'

Any idea ?

Crimson Wizard

#329
Quote from: Baguettator on Sun 13/04/2025 20:06:29I encounter a problem, it seems a bug from the v4 compiler.

Here's my code:

Code: ags
int ressource[TOTAL_RESSOURCES, TOTAL_CATEGORIES_RESSOURCES];
[...]
Ressource1[0].Text=String.Format("%d", ressource[nourriture][colo]); // This is line 1171

And the compiler displays an error :
Struct_Events_Colonie.asc(1171): An array index cannot follow an expression of type 'int'

Testing this kind of array in an empty project, accessing its elements seem to work.
Please give more details about the variables that you use here:

nourriture,
colo,
Ressource1.

Maybe break this long expression into smaller ones, that might help finding which exactly part has the error. Like this:
Code: ags
int num = ressource[nourriture][colo];
String str = String.Format("%d", num );
Ressource1[0].Text = str;

Other than that, if you are using variables from another script, double check that you have declared an import EXACTLY same way as the variable itself.

Baguettator

#330
Well, "nourriture" and "colo" are enum values :

Code: ags
enum Ress
{
nourriture=0,
...
};

enum Type
{
colo=1,
...
};

Will try to do as you say !

EDIT : OK, it was an error from me, but the compiler didn't indicate the right error/line : it was because I declared "int ressource" just before, but the problem is that "ressource" is already an int[][] in my script. The compiler should have told that "ressource already exists !

Crimson Wizard

#331
Quote from: Baguettator on Sun 13/04/2025 21:04:22EDIT : OK, it was an error from me, but the compiler didn't indicate the right error/line : it was because I declared "int ressource" just before, but the problem is that "ressource" is already an int[][] in my script. The compiler should have told that "ressource already exists !

Where exactly did you declare that other "ressource"?

It's allowed to declare another variable of the same name in a different scope. That is a common behavior in programming languages.

For example, if you have a global variable VARIABLE, you may still declare a local variable VARIABLE inside a function, and it will override the global one for the duration of that function.

Crimson Wizard

Updated to Alpha 21
(Please use download links in the first post)

This update contains all the new features and fixes from 3.6.2 RC3 (excepts ones related to backwards compatibility).

Editor:
- In General Settings added "GUI common controls handle only left mouse button" option.
- Fixed default values for Character and Object's Enabled and Visible properties set when upgrading a pre-4.0 game project.
- Fixed default value for "Use old-style voice clip naming rule" setting set when upgrading from older 4.0 alpha versions.
- Fixed newly created WFN fonts had their size multiplier property discarded when a game is compiled.

Compiler:
- Fixed a bug where naming a parameter like its function led to a crash.

Scripting:
- Support regular (non-managed) struct and array variable initializers, where you can specify their element values either in the order of their declaration or as a "name1: value, name2: value" sequence. For arrays the latter would be "0: value, 1: value" and so forth.
  NOTE: this works only for global variables at the moment.

Script API:
- Added DialogOptionsNumbering enum, to use when setting dialog options numbering mode.
- Added multiple new properties to Dialog type: OptionsBulletGraphic, OptionsGap, OptionsGUI, OptionsGUIX, OptionsGUIY, OptionsHighlightColor, OptionsMaxGUIWidth, OptionsMinGUIWidth, OptionsNumbering, OptionsPaddingX, OptionsPaddingY, OptionsReadColor, OptionTextAlignment. Most of these are replacing previously existing old-style variables in "game" struct and OPT_* options. OptionsGUIX/Y and OptionTextAlignment are completely new features.
- Added new game-wide option OPT_GUICONTROLMOUSEBUT that defines whether common GUI controls are affected by the right mouse button or not (InventoryWindows are excluded from this, because they have their own special handling for RMB).

Engine:
- Standard Dialog options now support Right-to-left text mode.
- Fixed a number of Room's script indexed properties not working correctly, such as: Room.Hotspots[], Room.Objects[], Room.Regions[], Room.WalkableAreas[], Room.Walkbehinds[].
- Fixed blend modes not handled correctly by Software renderer.
- Fixed certain blend modes not respecting transparency with OpenGL renderer.
- Fixed default dialog options highlight color had wrong value.
- Fixed Character.FaceDirection() not respecting blocking style parameter.
- Fixed characters and objects not making last planned step when moving.



This update has a new script syntax feature that allows to initialize a struct or array using a "initializer list". Unfortunately, this feature was not fully completed, and only works for global variables. There's a chance that it will be expanded to local variables too in the future updates.

Example for structs:
Code: ags
struct Location 
{ 
    float Longitude, Latitude; 
};
struct PointOfInterest
{
    int AdmissionFee;
    Location WhereItIs;
};

PointOfInterest EiffelTower = {
        WhereItIs: { Longitude: 48.8584, Latitude: 2.2945 }, 
        AdmissionFee: 20 + 3,    // ← Simple 'int' or 'float' expressions are possible
};

Example for arrays:
Code: ags
int Primes[10] = { 2, 3, 5, 7 };
Code: ags
bool IsPrime[10] = {
    2: true,     // ← means, IsPrime[2] is 'true'
    3: true,     // ← means, IsPrime[3] is 'true' etc.
    5: true,
    7: true,
};

Baguettator

Quote from: Crimson Wizard on Sun 13/04/2025 21:28:27
Quote from: Baguettator on Sun 13/04/2025 21:04:22EDIT : OK, it was an error from me, but the compiler didn't indicate the right error/line : it was because I declared "int ressource" just before, but the problem is that "ressource" is already an int[][] in my script. The compiler should have told that "ressource already exists !

Where exactly did you declare that other "ressource"?

It's allowed to declare another variable of the same name in a different scope. That is a common behavior in programming languages.

For example, if you have a global variable VARIABLE, you may still declare a local variable VARIABLE inside a function, and it will override the global one for the duration of that function.

For example :

Code: ags
// In another script :
int ressource [TOTAL_RESS, TOTAL_CATEG];
// This is exported and shared with all other scripts
// ...

// Then in Global Script :
function Myfunction ()
{
  int ressource=Random(8);
    String mot;
    if (ressource==0)
    {
      mot="Carburant";
      ressource=Random(2) + 2;
      if (player.Room==ROOM_EXP) ressource[carburant][exp]+=ressource; // => Compiler says an error here : "An array index cannot follow an expression of type 'int'"
// etc...
}

Crimson Wizard

#334
Quote from: Baguettator on Mon 14/04/2025 14:29:57For example :

Code: ags
// In another script :
int ressource [TOTAL_RESS, TOTAL_CATEG];
// This is exported and shared with all other scripts
// ...

// Then in Global Script :
function Myfunction ()
{
  int ressource=Random(8);

That is the situation that I was speaking about: a variable of same name but in another scope.

Following is a valid case in AGS script, as well as many other programming languages (C++, C#, Java, Python, etc):

Code: ags
int variable; // global variable

function f()
{
    int variable; // local function variable

    if (condition)
    {
        int variable; // local variable of a inner scope (1)
    }

    if (condition2)
    {
        int variable; // local variable of a inner scope (2)
    }
}

The compiler does not treat this as error.

Usually it's advised to invent a naming style in which global and local variables will have different names.
For example: call global variables with some prefix, like "gl_" , or use capital letters in their names, and call local variables in small letters only.
That will also help to quickly distinguish if that's a global or local variable when you see one in code:

Code: ags
int gl_Ressource [TOTAL_RESS, TOTAL_CATEG];

function Myfunction ()
{
  int ressource=Random(8);
  ....

Baguettator

Thanks for explanations !

But, it has changed recently ? I remember errors while compiling, with the message " 'ressource' is already defined". I didn't know it was possible now...

By the way, sorry it's a bit out of the thread because it's not a bug :)

Crimson Wizard

Quote from: Baguettator on Mon 14/04/2025 18:58:59But, it has changed recently ? I remember errors while compiling, with the message " 'ressource' is already defined". I didn't know it was possible now...

No, it has always been like this. The error happens when you have 2 variables of same name in the same scope. Like, two global variables.

Baguettator

Hi !

I'm using the last version of AGS 4.0, and it seems giving a slider a background image doesn't give it the same size as the image itself. So it's a bit annoying because you have to drag it manually or enter the right values in the editor panel.

Is it a bug ?

Crimson Wizard

Quote from: Baguettator on Sat 26/04/2025 12:11:45I'm using the last version of AGS 4.0, and it seems giving a slider a background image doesn't give it the same size as the image itself. So it's a bit annoying because you have to drag it manually or enter the right values in the editor panel.

If you mean that the slider does not resize when you add a image, similar to button, then it has always been like this.
Buttons are the only controls that resize to a new image.
I suppose it's not too hard to implement such behavior though.

Baguettator

That's exactly what I mean :) Sorry for my bad english...

It could be a quality of life feature ! There is no reason it doesn't resize like buttons ?

SMF spam blocked by CleanTalk