I'm having a hard time displaying text and pictures.

Started by Tentacles, Mon 15/03/2010 15:33:07

Previous topic - Next topic

Tentacles

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!");
}

Crimson Wizard

You have a weird syntax error there:

Code: ags
 Overlay "textOverlay;



It must be:

Code: ags
 Overlay * textOverlay;


Use * (asteriks) to declare pointers.


Also closing bracket is missing for Overlay.CreateTextual call.

Tentacles


    Weird, I ended up getting the same error. Should I just send a copy of the game?

Crimson Wizard

Better just post whole room script.
Or, at least point out what is line 7 in room.asc.

Calin Leafshade

Youre also missing the end bracket from this line

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


it should be

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


Calin Leafshade

Oh yeah.. sorry.

...

oh and by the way you should use an asterisk for the pointer definition.


Tentacles

#8
     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.";

Crimson Wizard

There's still a missing bracket at the end of function call.
See Calin's detailed explanation above.

Tentacles


      Well I didnt get any errors this time, but it still didnt display the text.

monkey0506

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:

Code: ags
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);
}

Tentacles

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:

Code: ags
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.

Khris

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.

monkey0506

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:

Code: ags
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.

Tentacles


  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.

barefoot

maybe the font color is almost the same as the background so you can't see it.

Code: ags

 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

I May Not Be Perfect but I Have A Big Heart ..

Khris

7 is a dark gray.

Is the function properly linked in the events pane?

Tentacles



     I'll need to find out to change the colors. Also, whats this about properly linking it?

Andail

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?

SMF spam blocked by CleanTalk