Jump to content


Photo

Wingman Sam + Draw_Text Problem


  • Please log in to reply
16 replies to this topic

#1 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 02 May 2012 - 05:53 PM

Hello All,
I’m a newbie to Games Maker (GM8 Pro) and this is my first post, so please be gentle...;-)
I have, what is probably a very simple, problem which I was hoping someone might be able to help me with....

I am trying to modify the ‘Wingman Sam’ game (from the original ‘Game Maker’s Apprentice’ book), in order to make it an educational game.
I’d like to display some text (i.e. a sum or answer) above both the player’s plane and the Enemy planes.
I’ve managed to do this with the player’s plane by adding a Draw event/Draw Text action (via the Drag N Drop GUI) to the player’s plane object (obj_plane1) (the word ‘TEST’ in the screenshot below).

Posted Image

However, the problem comes trying to reproduce this for the Enemy planes....

The enemy planes are not actually placed (as objects) in the room/playing area; rather five instances/planes are created by (D & D) ‘Create Instance’ actions in a Time Line (as per the book's instructions).
When I modify the actual ‘obj_enemy_basic’ object, only the first plane (in the wave of 5) displays the text, the rest do not (i.e. only the first plane displays the text ‘Answer’, as shown in the pic above).

I am thinking maybe it has something to do with the planes being dynamically created, so I thought I would replace the ‘Create Instance’ actions with some script (below), however this does not work and there is no text displayed above the enemy planes at all!

{
// Create a ‘Wave’ of planes, with text above them
var plane1, plane2, plane3, plane4, plane5;
plane1 = instance_create(80,-40,obj_enemy_basic);
plane2 = instance_create(200,-40,obj_enemy_basic);
plane3 = instance_create(320,-40,obj_enemy_basic);
plane4 = instance_create(440,-40,obj_enemy_basic);
plane5 = instance_create(560,-40,obj_enemy_basic);
draw_set_font(fnt_panel);
draw_set_color(c_red);
draw_sprite(spr_enemy_basic,-1,plane2.x-50,plane2.x-25);
draw_text(plane1.x-25,plane1.y-50,'Answer');
draw_text(plane2.x-25,plane2.y-50,'Answer');
draw_text(plane3.x-25,plane3.y-50,'Answer');
draw_text(plane4.x-25,plane4.y-50,'Answer');
draw_text(plane5.x-25,plane5.y-50,'Answer');
}


It’s probably something incredibly stupid on my part, but does anyone know what I am doing wrong?

Thanks in advance

Roy
  • 0

#2 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 02 May 2012 - 05:59 PM

where do you try to draw the text, in a different object?
If so, try the with function:
with object_enemy_basic
draw_text(x-25,y-50,'Answer');
  • 0

#3 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 03 May 2012 - 08:49 AM

Thanks for the reply....

I tried drawing the text within the obj_enemy_basic (only displays text for one plane, not all five), so the script above was placed as a 'moment' within a time line, not within an actual object

I would have thought that by placing the text within the obj_enemy_basic, it would display with every instance of the object?, but that does not seem to be the case.
  • 0

#4 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 03 May 2012 - 10:07 AM

OK, just an update.... I found the following link Link, and this is what I am thinking

When I put the Draw_Text (as a D & D) in the draw event of the obj_enemy_basic plane, only one plane displays the text, none of the other (dynamically created) planes in the wave display the text. I note from the above tutorial that I should have placed the object(s) in the room, but at the moment all the enemy planes are dynamically created in a time line (in order to create a 'wave' of planes).

I tried this piece of code in the script (called from the time line) and found that it works

draw_text(200,200,'Press any key to continue.');
screen_refresh();
keyboard_wait();

This is what I noted:

1. That the original Draw_text code (from the previous post) is probably executing, but I suspect it is before the planes enter the room (they fly in from the top of the screen)
2. With the code above, I notice that the text only displays if using the screen_refresh() function, and with out the Keyboard_wait(), the text literally flashes on and then off the screen in a split second.

So I am wondering, am I going about this in the right way? How do I dynamically create these wave of planes and have them display text at the same time?

Yours Confused
  • 0

#5 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 03 May 2012 - 03:12 PM

to show text above the plane from within the plane using D&D:
draw variable:
variable: "answer"
x: 0
y: -32
relatif checked
  • 0

#6 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 03 May 2012 - 05:17 PM

to show text above the plane from within the plane using D&D:
draw variable:
variable: "answer"
x: 0
y: -32
relatif checked


Hi, thanks for the reply, I have done this before (within obj_enemy_basic), but it only seems to work on the first, of 5 horizontally aligned, planes. The text does not show up on the other 4 planes in the wave.

The planes are not actual objects placed on the room/playing area, but are dynamically created within the time line.

Why does the code you have suggested work on the first instance of the enemy plane, but not the other four in the line?

Thanks
  • 0

#7 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 03 May 2012 - 05:53 PM

can you upload a gmk/gm81 file?
  • 0

#8 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 03 May 2012 - 06:28 PM

can you upload a gmk/gm81 file?


Thanks for the reply

194X

A wave of enemy planes are created from the time line (time_level1, step 60)

The enemy plane (obj_enemy_basic) contains a Draw event with a Draw_Text action, but this seems to only show up on the first of the five planes (created in the aforementioned timeline).

Although I have disabled it, I was calling the script (script0) from the timeline (via the Execute Script action), but while to commands to create the planes were working OK, the Draw_Text commands were not....

Thanks in advance for this

Roy
  • 0

#9 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 03 May 2012 - 06:44 PM

to show text above the plane from within the plane using D&D:
draw variable:
variable: "answer"
x: 0
y: -32
relatif checked


Hi, thanks for the reply, I have done this before (within obj_enemy_basic), but it only seems to work on the first, of 5 horizontally aligned, planes. The text does not show up on the other 4 planes in the wave.

The planes are not actual objects placed on the room/playing area, but are dynamically created within the time line.

Why does the code you have suggested work on the first instance of the enemy plane, but not the other four in the line?

Thanks


You haven't done what I said in that message, you really don't have use x or y, the relatif button will take care of that.
so only use the -25 and -50 and delete the part you've written before those 2 numbers.

Edited by jo-thijs, 03 May 2012 - 06:44 PM.

  • 0

#10 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 03 May 2012 - 07:06 PM

to show text above the plane from within the plane using D&D:
draw variable:
variable: "answer"
x: 0
y: -32
relatif checked


ahhhh A thousand Thanks You's!!!!

I misunderstood the original post!

Out of interest, how would this translate into GML if I wanted to call it in script0 from the timeline? Would it be possible?
  • 0

#11 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 04 May 2012 - 03:55 PM

Sorry, i'll rephrase that....

Now that the text is being displayed within the obj_enemy_basic object itself, how do I programmatically access the object and change the text to something else?

i.e. From a script, call the object's draw event and then the Draw_text function?

i.e. plane2.draw_text(x,y,'Another Piece of Text'); (unfortunately this just generates an error)

Thanks in advance?

Edited by RoyBenson, 04 May 2012 - 04:05 PM.

  • 0

#12 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 04 May 2012 - 04:06 PM

this can not be doen efficiently through D&D, but is very easy in gml.
you use this code to create an enemy:
with instance_create(the x-coordinate, the y-coordinate,obj_enemy_basic) mytext="The name";
and then you draw the variable mytext rather then drawing pure text.
  • 0

#13 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 04 May 2012 - 04:40 PM

Thanks for this, but I am having trouble getting it to work...

At the moment I have the following code

plane1 = instance_create(80,-40,obj_enemy_basic);
plane2 = instance_create(200,-40,obj_enemy_basic);
plane3 = instance_create(320,-40,obj_enemy_basic);
plane4 = instance_create(440,-40,obj_enemy_basic);
plane5 = instance_create(560,-40,obj_enemy_basic)

I then want to access the individual plane objects and change their texts

If I replace the above with :

with instance_create(80,-40,obj_enemy_basic) mytext="One";
with instance_create(200,-40,obj_enemy_basic) mytext="Two";
with instance_create(320,-40,obj_enemy_basic) mytext="Three";
with instance_create(440,-40,obj_enemy_basic) mytext="Four";
with instance_create(560,-40,obj_enemy_basic) mytext="Five";

How do I access the individual planes, change their text and then display the new text?

i.e. 
Plane1.mytext = '3';
Plane2.mytext = '5';
Plane3.mytext = '7'; 
Plane4.mytext = '9';

Draw_text(Plane1.x, Plane1.y, mytext);
Draw_text(Plane2.x, Plane2.y, mytext);

Does this make sense?
  • 0

#14 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 04 May 2012 - 05:22 PM

the replaced thing is good, but to draw their text you just have to replace the draw text action by the draw variable action with the same coordinates and also relatif and mytext as variable.
  • 0

#15 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 04 May 2012 - 05:47 PM

the replaced thing is good, but to draw their text you just have to replace the draw text action by the draw variable action with the same coordinates and also relatif and mytext as variable.


Thanks for that,

I've done what you suggested, and the planes are created and display the text (as per below)

with instance_create(80,-40,obj_enemy_basic) mytext="One";
with instance_create(200,-40,obj_enemy_basic) mytext="Two";
with instance_create(320,-40,obj_enemy_basic) mytext="Three";
with instance_create(440,-40,obj_enemy_basic) mytext="Four";
with instance_create(560,-40,obj_enemy_basic) mytext="Five";

However, now that the planes are displaying the initial values ('One', 'Two', 'Three' etc...), how do I change these variables on the fly and then re-display them?

i.e. I now want to access the third plane in the wave (plane3), change the text (from "Three" to, say, "Seven") and then have that reflected on screen.

i.e. something like:
plane3.mytext="Seven";
draw_text(plane3.x,plane3.y, mytext);


As far as I can see, I cannot access the instances that I have created, and even if I use the old code ( i.e. plane1 = instance_create...mytext="Three"; ), I can't seem to access the mytext variable and reset it with a new value....

Any ideas?

Thanks
  • 0

#16 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 3102 posts
  • Version:GM8.1

Posted 04 May 2012 - 07:15 PM

You can use some if functions, like:
if mytext=="Three"
mytext="Seven";else
if mytext=="Four"
mytext="Eight";else
...

I don't know where you have to put it because I don't know when you want them to change names.
  • 0

#17 RoyBenson

RoyBenson

    GMC Member

  • GMC Member
  • 31 posts
  • Version:Unknown

Posted 05 May 2012 - 10:52 AM

You can use some if functions, like:
if mytext=="Three"
mytext="Seven";else
if mytext=="Four"
mytext="Eight";else
...

I don't know where you have to put it because I don't know when you want them to change names.


Thanks! Finally sorted it!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users