Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tentacles on Mon 15/03/2010 15:33:07

Title: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Mon 15/03/2010 15:33:07
Failed to save room room1.crm; details below
room1.asc(7): Error (line 7): Cannot declare local instance of managed type

   This is the error I seem to keep getting.

And this is the code.

// room script file

function room_AfterFadeIn()
{
     Overlay "textOverlay;
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.";
     Wait(300);
}


   Any ideas on what might be wrong with the code?

  I also seem to keep getting an error on cTentacles.Say

function room_AfterFadeIn()
{
        cTentacles.Say("Hello World!");
}
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Mon 15/03/2010 15:34:52
You have a weird syntax error there:

Overlay "textOverlay;


It must be:

Overlay * textOverlay;

Use * (asteriks) to declare pointers.


Also closing bracket is missing for Overlay.CreateTextual call.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Mon 15/03/2010 15:38:21

    Weird, I ended up getting the same error. Should I just send a copy of the game?
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Mon 15/03/2010 15:39:39
Better just post whole room script.
Or, at least point out what is line 7 in room.asc.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Calin Leafshade on Mon 15/03/2010 15:43:18
Youre also missing the end bracket from this line

textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.";

it should be

textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.");
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Mon 15/03/2010 15:48:50
I've told that above, Calin  ::)
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Calin Leafshade on Mon 15/03/2010 15:51:23
Oh yeah.. sorry.

...

oh and by the way you should use an asterisk for the pointer definition.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Mon 15/03/2010 15:52:40
 :P
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Mon 15/03/2010 17:50:24
     That is my whole script, I have not gotten any script to work.

  This is line 7

textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.";
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Mon 15/03/2010 18:00:39
There's still a missing bracket at the end of function call.
See Calin's detailed explanation above.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Mon 15/03/2010 20:35:30

      Well I didnt get any errors this time, but it still didnt display the text.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: monkey0506 on Mon 15/03/2010 20:43:43
That's because you're declaring the Overlay within a function. This is what we call variable/pointer scope.

Basically what's happening is that your Overlay* "textOverlay" only exists within the scope or body of the function. As soon as the function ends your pointer no longer exists. You no longer have a valid pointer pointing to the created overlay.

Because of AGS's garbage collection the overlay gets deleted as soon as there are no longer any pointers pointing to it.

To elaborate on what I mean:

function room_AfterFadeIn()
{
     Overlay *textOverlay; // pointer textOverlay is created without an initial value and holds the value null
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay."); // a new overlay is created and the textOverlay pointer is assigned to point to it
     Wait(300);
} // the room_AfterFadeIn function terminates, releasing all existing variables and pointers defined within the function
// after the textOverlay pointer is released, there is no longer a valid pointer pointing to the created overlay
// the created overlay is "cleaned up" and removed


The way you resolve your overlay being detected as garbage? Define the pointer outside of the function so it isn't released from memory:
Overlay *textOverlay;

function room_AfterFadeIn()
{
     // removed the definition of the pointer from the function
     // placed it outside the function instead
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.");
     Wait(300);
}
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Mon 15/03/2010 21:52:27
Quote from: monkey_05_06 on Mon 15/03/2010 20:43:43
That's because you're declaring the Overlay within a function. This is what we call variable/pointer scope.

Basically what's happening is that your Overlay* "textOverlay" only exists within the scope or body of the function. As soon as the function ends your pointer no longer exists. You no longer have a valid pointer pointing to the created overlay.

Because of AGS's garbage collection the overlay gets deleted as soon as there are no longer any pointers pointing to it.

To elaborate on what I mean:

function room_AfterFadeIn()
{
     Overlay *textOverlay; // pointer textOverlay is created without an initial value and holds the value null
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay."); // a new overlay is created and the textOverlay pointer is assigned to point to it
     Wait(300);
} // the room_AfterFadeIn function terminates, releasing all existing variables and pointers defined within the function
// after the textOverlay pointer is released, there is no longer a valid pointer pointing to the created overlay
// the created overlay is "cleaned up" and removed


The way you resolve your overlay being detected as garbage? Define the pointer outside of the function so it isn't released from memory:
Overlay *textOverlay;

function room_AfterFadeIn()
{
     // removed the definition of the pointer from the function
     // placed it outside the function instead
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.");
     Wait(300);
}



   Are you even understanding my question? I did the stuff you guys described, and its not working. I'll make a video later showing you what I mean if that's what it takes.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Khris on Mon 15/03/2010 22:10:37
You are having incredibly basic problems here, using bad syntax and whatnot.
Furthermore, "it's not working" isn't very helpful.

People try to help you, and when you fuck up again, you get all frustrated and condescending, senselessly quoting long answers in the process.

You need to chill and remember that you don't pay us for helping you.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: monkey0506 on Mon 15/03/2010 22:13:34
Tentacles, it would appear you didn't even read the post that you quoted. If you did then you gave zero indication what was/is still wrong.

The code I provided you with (not the first example with the gray background but rather the second example which I did not mark as code so that I could use colorization to indicate what you needed to fix) works exactly as what you have described as the effect you are trying to achieve.

If it is not working then it is user error.

If you copy and paste this code exactly in place of your existing code, I guarantee you it will work:

Overlay *textOverlay;

function room_AfterFadeIn()
{
     // removed the definition of the pointer from the function
     // placed it outside the function instead
     
     textOverlay = Overlay.CreateTextual(160, 160, 100, Game.NormalFont, 7,  "This is the first text overlay.");
     Wait(300);
}


Note that this is the exact same code I already gave you.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Tue 16/03/2010 08:23:04

  monkey_05_06, once again you misread what I just said, I'm saying the text isnt displaying. I'm not getting any more errors, I'm just not able to see the text be displayed.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: barefoot on Tue 16/03/2010 09:28:45
maybe the font color is almost the same as the background so you can't see it.


Overlay.CreateTextual(160, 160, 400,  Game.NormalFont, 59360,  "This is the first text overlay.");
    Wait(300);


Changing the  number to 59360 gives a yellow font.
Changing to the  number  to 59391 gives a white font.

Use code numbers generated in your Colours tab.

just food for thought

barefoot

Title: Re: I'm having a hard time displaying text and pictures.
Post by: Khris on Tue 16/03/2010 10:07:26
7 is a dark gray.

Is the function properly linked in the events pane?
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Tue 16/03/2010 10:26:56


     I'll need to find out to change the colors. Also, whats this about properly linking it?
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Andail on Tue 16/03/2010 10:32:43
Tentacles, right now you seem to echo everything that's said here and make it into a question. Maybe you need to investigate the basics of AGS a bit more on your own, and give coding a more step-by-step approach?
Title: Re: I'm having a hard time displaying text and pictures.
Post by: monkey0506 on Tue 16/03/2010 11:18:27
Tentacles, not to be rude, but honestly you can't accuse me of misreading what you said because you didn't actually say anything. Saying "it doesn't work" gives absolutely no indication what is happening.

In order for us to be able to help you we are going to have to know what is going on. If the text is not displaying but everything else seems to be functioning normally, say so, not just that it isn't working. If you're getting any type of error message, which I understand you said you are not, but if you were, then you should tell us not just that you are getting an error, but what it says.

In retrospect regarding my post about the scope with that Wait statement the Overlay* would still have scope for approximately 7.5 seconds at normal game speed which should be plenty of time for you to see the text, so I may have been talking a bit of bullocks as to why it wasn't showing up. That said however, I was correct that the code is completely valid.

Regarding the events pane, as has been said, this is one of the most basic steps to working with the AGS 3 editor (comprising all versions of AGS 3.0 and higher to date, up to 3.2 RC 3). Seeing as this is a room function you will need to open the room for editing (as you would to draw walkable areas and such, but don't display any of these, just let it display the room background only, "Nothing"). By default your project tree and such will be along the right-hand side of the editor. If you have moved it to the left then you will need to take that into consideration for the information that follows.

In the bottom right-hand quadrant of the editor window you should have the Properties pane. This is where you can set various different properties of the item currently displayed in the active tab. If you look just above the Properties pane you should see a lightning bolt-shaped icon. Click on this. This brings you to the Events pane.

For each event listed in the Events pane there is a text box associated with it. You can either type in a function name manually, or you can click the ellipses (...) button which will attempt to automatically create the function with the default name.

Please note that when you are putting anything in these text boxes, you will only use the function name. This is particularly important if you ever need to link a function that requires parameters. You can't just link whatever function you want though because the function must have the same parameters, including the number and types of those parameters, in order for the function to be properly linked. The "Player enters room (after fade-in)" event gets linked to a function just like yours with no parameters at all. So if you want to "properly link" your event handler (your function) to the event itself so the function will actually be called, then you need to type into the appropriate text box "room_AfterFadeIn" (without the quotes around it. Do not include any parenthesis, braces, or otherwise, just the name of the function.

Once this is done, with the code that has been provided, you will see the text.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Calin Leafshade on Tue 16/03/2010 12:24:44
Quote from: monkey_05_06 on Tue 16/03/2010 11:18:27
Tentacles, not to be rude,

I love this opening statement.. As if tentacles is a completely valid thing to call someone..

"Listen, Tentacles honey...."
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Crimson Wizard on Tue 16/03/2010 15:31:54
By the way, just a sudden thought. Does the room actually have a background? I have a feeling that without background nothing would show up, even GUIs.

Then again, where's that video you mentioned above?
Title: Re: I'm having a hard time displaying text and pictures.
Post by: monkey0506 on Tue 16/03/2010 15:33:50
Without a background I'm pretty sure the game wouldn't run at all which is why the default game template now has an empty room with a blank, black background which runs fine.
Title: Re: I'm having a hard time displaying text and pictures.
Post by: Tentacles on Tue 16/03/2010 18:19:55


    Already its finally working. Apparently my computer, because its running vista, has the tendency tlo switch colors to vista basic.