Screenshots in game saves

Started by Silent Bob, Tue 10/04/2018 23:05:33

Previous topic - Next topic

bx83

I'm wanting to create the save-game system of 3 screenshotted games above.
However I keep getting "Attributes of identifier do not match prototype" on the first line of code (DynamicSprite *buttonSavePic1;). Not sure what this error means (other than I can program Basic but not C++ :P)

global.asc:
Code: ags
DynamicSprite *buttonSavePic1;
DynamicSprite *buttonSavePic2;
DynamicSprite *buttonSavePic3;

function ShowSaveGUI() {
  buttonSavePic1 = DynamicSprite.CreateFromSaveGame(1, 171, 96);
  if (buttonSavePic1 != null) buttonSaveSlot1.NormalGraphic = buttonSavePic1.Graphic;
  
  buttonSavePic2 = DynamicSprite.CreateFromSaveGame(2, 171, 96);
  if (buttonSavePic2 != null) buttonSaveSlot2.NormalGraphic = buttonSavePic2.Graphic;
  
  buttonSavePic3 = DynamicSprite.CreateFromSaveGame(3, 171, 96);
  if (buttonSavePic3 != null) buttonSaveSlot3.NormalGraphic = buttonSavePic3.Graphic;
  
  gSaveLoad.Visible = true;
}


function buttonSaveSlot1_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  SaveGameSlot(1, "Save 1");  
  Wait(GetGameSpeed()*1/2);
  gSaveLoad.Visible=true;
}

function buttonSaveSlot2_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  SaveGameSlot(2, "Save 2");  
  Wait(GetGameSpeed()*1/2);
  gSaveLoad.Visible=true;
}

function buttonSaveSlot3_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  SaveGameSlot(3, "Save 3");  
  Wait(GetGameSpeed()*1/2);
  gSaveLoad.Visible=true;
}

function btnSave_OnClick(GUIControl* control, MouseButton button)
{
  gPanel.Visible = false;
  mouse.UseDefaultGraphic();
  gIconbar.Visible = true;
  Wait(1);
  
  ShowSaveGUI();
}


function buttonLoad1_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  RestoreGameSlot(1);
  mouse.UseModeGraphic(eModePointer);
  gIconbar.Visible=true;
}

function buttonLoad2_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  RestoreGameSlot(2);
  mouse.UseModeGraphic(eModePointer);
  gIconbar.Visible=true;
}

function buttonLoad3_OnClick(GUIControl *control, MouseButton button)
{
  gSaveLoad.Visible=false;
  RestoreGameSlot(3);
  mouse.UseModeGraphic(eModePointer);
  gIconbar.Visible=true;
}


Apart from the other 27 minor bugs in this code, can anyone help me with the error?

Crimson Wizard

Have you declared buttonSavePic1 anywhere else, for example as an import?

bx83

No. I haven't exported it or imported in .ash.

bx83

I tried getting rid of them as global variables, and writing like this:

Code: ags


//no var declarations


function ShowSaveGUI() {
  DynamicSprite *buttonSavePic1 = DynamicSprite.CreateFromSaveGame(1, 192, 342);
  if (buttonSavePic1 != null) buttonSaveSlot1.NormalGraphic = buttonSavePic1.Graphic;
  
  DynamicSprite *buttonSavePic2 = DynamicSprite.CreateFromSaveGame(2, 192, 342);
  if (buttonSavePic2 != null) buttonSaveSlot2.NormalGraphic = buttonSavePic2.Graphic;
  
  DynamicSprite *buttonSavePic3 = DynamicSprite.CreateFromSaveGame(3, 192, 342;
  if (buttonSavePic3 != null) buttonSaveSlot3.NormalGraphic = buttonSavePic3.Graphic;
  
  gSaveLoad.Visible = true;
}


However, now I have it telling me:
"Local variable cannot have the same name as an import"
for first line: 'DynamicSprite *buttonSavePic1 = DynamicSprite.CreateFromSaveGame(1, 192, 342);'

Searched for all other instances of buttonSavePic1 - they're only in this line. Confounded.

Crimson Wizard

#24
Quote from: bx83 on Tue 27/04/2021 09:36:48
"Local variable cannot have the same name as an import"

But this means that you have them somewhere as an import.

Try to do Edit -> Find All and chose "Look In: Current Project".

bx83

Nowhere else - all in ShowSaveGUI().

Crimson Wizard

#26
What about Global Variables panel? that's the last place it can be.

EDIT: Well, in theory it may be also assigned as a "script name" to something, which also would declare it as import. Just to mentioned hypothetical possibility.

Maybe try to search for this name in all project files using explorer, or other tool that searches in files on disk.

bx83


Crimson Wizard

#28
Well, either it is somewhere, or this is a bug in script compiler. In the last case I will only be able to do anything if I have a project source and can test it myself...

What will happen if you put this variable, or all the ShowSaveGUI code, in a new script on top of the script list?

EDIT: when I place this script in a test game, it compiles properly (I just had to add necessary GUI).

bx83

I put ShowSaveGUI() only in a new script called 'testsaveload', deleted it from GlobalScript.asc, ran it with F5, and now it's telling me the same "Local variable cannot have the same name as an import" on the same first line of function.
(and it's on top of all scripts)

Crimson Wizard

Quote from: bx83 on Tue 27/04/2021 10:00:34
I put ShowSaveGUI() only in a new script called 'testsaveload', deleted it from GlobalScript.asc, ran it with F5, and now it's telling me the same "Local variable cannot have the same name as an import" on the same first line of function.
(and it's on top of all scripts)

Well, I have only 1 thing left to suggest, that somehow it is assigned as a script name to some game element. To check if it is, maybe try opening "Game.agf" file in your project with a notepad and search there.

bx83

#31
Solved it - I named the buttonSavePic1 after a GUI element. I'll go and shoot myself now.

btw: should I have GlobalScript at the bottom of the tree?

Khris

I don't think it has to be at the bottom, but a script can only use other script's functions and variables if the other script is further up the tree.
And since the global script contains all GUI buttons handlers and the like, you'll usually want to keep it at the bottom.

SMF spam blocked by CleanTalk