Jump to content


Photo

How to deactivate self?


  • Please log in to reply
15 replies to this topic

#1 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 03:59 AM

The idea is to pass the current menu id to a submenu, deactivate itself, then reactivate when the submenu is exited.
But the calling menu is still active despite on screen code below in calling menu.

    ins = instance_create(1,1,obj_options)
    ins.return_to=id;
    instance_deactivate_object(id);


Please what am I doing wrong here?
I suppose I can destroy/create the calling menu object but I was hoping for a deactivate/activate solution.

Edited by decroded, 09 May 2012 - 04:02 AM.

  • 0

#2 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 04:55 AM

if you use GM 8(.1 if it is only for it)
try:
instance_deactivate_object(self);

  • 0

#3 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 05:03 AM

if you use GM 8(.1 if it is only for it)
try:

instance_deactivate_object(self);

Oh crap my bad - my controller was creating the menu if it doesn't exist (i.e. also happening when !active) :skull:
Bot your code and mine works now.

Ok different question then sorry, is there a way to set the transition (e.g. fade from black) for first coming into the initial room?
I'm doing it manually hence this creation code...

Edited by decroded, 09 May 2012 - 05:06 AM.

  • 0

#4 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 05:23 AM

to move from room to room?
or what?Posted Image
  • 0

#5 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 05:38 AM

to move from room to room?
or what?Posted Image


Well I made basic scr_room_goto below since I'm using only that transition (its fade to & from black).
I'm just wondering if there's a way to get this effect when entering the first room in the game somehow.
At the moment I'm using timer var in obj_control and draw a black rectangle with reducing alpha to simulate the effect but I'd like to know how to do without that method.
Other way I've done before is an rm_init which is just an initialisation room that is exited immediately but lets you do a transition (amongst other things).

//--change room with transition...
transition_kind=21;
transition_steps=80;
room_goto(argument0)

  • 0

#6 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 05:41 AM

why can't you use that?Posted Image
or does it only work for exiting room?
  • 0

#7 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 06:06 AM

why can't you use that?Posted Image
or does it only work for exiting room?

I don't know where to call it from.
Like how to get in before the first room has already started.
If I use room start event to set transition then goto same room once, there is still the initial flash of the room at full brightness before the transition.
Only other way I can see is with an rm_init or something like that :-/

EDIT: and yeah seems to me to only be when you leave a room that the transition takes effect (hard to tell really)

Edited by decroded, 09 May 2012 - 07:45 AM.

  • 0

#8 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 06:14 PM


why can't you use that?Posted Image
or does it only work for exiting room?

I don't know where to call it from.
Like how to get in before the first room has already started.
If I use room start event to set transition then goto same room once, there is still the initial flash of the room at full brightness before the transition.
Only other way I can see is with an rm_init or something like that :-/

EDIT: and yeah seems to me to only be when you leave a room that the transition takes effect (hard to tell really)

ok I fell asleep and got an idea!
use the room creation code!
disable everything and put a square with alpha set to 1, then decrease it by 0.1
once it hits 0.1 or less activate all objects!
  • 0

#9 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 10:01 PM



why can't you use that?Posted Image
or does it only work for exiting room?

I don't know where to call it from.
Like how to get in before the first room has already started.
If I use room start event to set transition then goto same room once, there is still the initial flash of the room at full brightness before the transition.
Only other way I can see is with an rm_init or something like that :-/

EDIT: and yeah seems to me to only be when you leave a room that the transition takes effect (hard to tell really)

ok I fell asleep and got an idea!
use the room creation code!
disable everything and put a square with alpha set to 1, then decrease it by 0.1
once it hits 0.1 or less activate all objects!

Except that code will only execute once instead of looping.
I'm doing the fading rectangle now but I suppose using a little self-destructing fader object created by room creation code is NEATER than having unwanted junk in my obj_control like I have now.
Still a workaround but thats ok if thats how it needs to be.

Thanks mate :biggrin:
  • 0

#10 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 10:07 PM

you know there's a DnD action that let's you go to a specified room and use a transition!

Edited by creators124, 09 May 2012 - 10:07 PM.

  • 0

#11 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 10:16 PM

you know there's a DnD action that let's you go to a specified room and use a transition!

:yucky:
I don't like doing much D&D coz when I wanna do the same thing in code some time I have to waste time working it out.
Its also ugly as I try to centralise my logic in as few places as practical so its easier to debug, reuse etc.

With all the little places logic can hide in GM I sometimes find its a trade-off between neat little solutions and being able to easily see/remember how you did it later...
  • 0

#12 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 10:46 PM

Transitions
When you move from one room to another you can select a transition. To set the transition to the next frame you must set the variable called transition_kind. If you assign a value larger than 0 to it the corresponding transition is used for the next room transition. It only affect the next transition. After this the value is reset to 0, which indicates no transition.


transition_kind Indicates the next room transition. You can use the following builtin values

0 = no effect
1 = Create from left
2 = Create from right
3 = Create from top
4 = Create from bottom
5 = Create from center
6 = Shift from left
7 = Shift from right
8 = Shift from top
9 = Shift from bottom
10 = Interlaced from left
11 = Interlaced from right
12 = Interlaced from top
13 = Interlaced from bottom
14 = Push from left
15 = Push from right
16 = Push from top
17 = Push from bottom
18 = Rotate to the left
19 = Rotate to the right
20 = Blend the rooms
21 = Fade out and in

transition_steps Indicates the number of steps in the transition. The more steps, the longer the transition takes. Default is 80.
transition_define(kind,name) You can actually create your own transitions. To this end you must define a script (possibly in an extension package) to do the transition. With this function you can then add the transition to the system. kind is the index of the transition (either a new one or an existing transitions). name is the name of the script. Note that the name of the script is a string! So there must be quotes around it. Note that this is really advanced stuff. The script must take five arguments: a surface with the image of the previous room, a surface with the image of the next room, the width of the surfaces, the height of the surfaces, and the fraction of the transition (between 0 and 1). It must then draw the image using the two surfaces.
transition_exists(kind) This function returns whether a transition of the indicated kind exists.
Please note that transitions do not work when using 3d graphics. Also, room transitions in general do not work correctly when the sizes of the rooms (or to be more precise of the region on the screen) are not the same.

sorry if it is long but it is the help file!
code to do room transitions:
transition_kind = 21;
fade out and in it is!
I know you use this but you can still use this for transition.

Edited by creators124, 09 May 2012 - 10:47 PM.

  • 0

#13 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 10:53 PM

Transitions
When you move from one room to another you can select a transition. To set the transition to the next frame you must set the variable called transition_kind. If you assign a value larger than 0 to it the corresponding transition is used for the next room transition. It only affect the next transition. After this the value is reset to 0, which indicates no transition.


transition_kind Indicates the next room transition. You can use the following builtin values

0 = no effect
1 = Create from left
2 = Create from right
3 = Create from top
4 = Create from bottom
5 = Create from center
6 = Shift from left
7 = Shift from right
8 = Shift from top
9 = Shift from bottom
10 = Interlaced from left
11 = Interlaced from right
12 = Interlaced from top
13 = Interlaced from bottom
14 = Push from left
15 = Push from right
16 = Push from top
17 = Push from bottom
18 = Rotate to the left
19 = Rotate to the right
20 = Blend the rooms
21 = Fade out and in

transition_steps Indicates the number of steps in the transition. The more steps, the longer the transition takes. Default is 80.
transition_define(kind,name) You can actually create your own transitions. To this end you must define a script (possibly in an extension package) to do the transition. With this function you can then add the transition to the system. kind is the index of the transition (either a new one or an existing transitions). name is the name of the script. Note that the name of the script is a string! So there must be quotes around it. Note that this is really advanced stuff. The script must take five arguments: a surface with the image of the previous room, a surface with the image of the next room, the width of the surfaces, the height of the surfaces, and the fraction of the transition (between 0 and 1). It must then draw the image using the two surfaces.
transition_exists(kind) This function returns whether a transition of the indicated kind exists.
Please note that transitions do not work when using 3d graphics. Also, room transitions in general do not work correctly when the sizes of the rooms (or to be more precise of the region on the screen) are not the same.

sorry if it is long but it is the help file!
code to do room transitions:
transition_kind = 21;
fade out and in it is!
I know you use this but you can still use this for transition.

Not sure why you post this coz yeah I am doing that and got it from the manual.
I just meant D&D in general doesn't help sharpen coding skills...
  • 0

#14 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 11:14 PM

you could always draw a square that fades out.
  • 0

#15 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 09 May 2012 - 11:33 PM

you could always draw a square that fades out.

Yeah I do I said I was doing it manually but sorry I didn't explain that I was doing it using a rectangle from obj_control.
I have now moved the logic into an obj_intro which gets called from obj_control room start event (for when you quit back to main menu) as per below code.
Its much nicer having this logic cleaned out of obj_control so thanks for your suggestion :biggrin:


obj_intro (just a fader at this point since I haven't made an intro)
CREATE:
fade_alpha=1;
fade_rate=0.03;
instance_deactivate_all(true);
DRAW:
if (fade_alpha > 0)
{
    draw_set_color(c_black);
    draw_set_alpha(fade_alpha);
    draw_rectangle(0,0,room_width,room_height,false);
    fade_alpha-=fade_rate;
} else {
    instance_destroy();
    instance_activate_all();
}

  • 0

#16 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 10 May 2012 - 12:07 AM


you could always draw a square that fades out.

Yeah I do I said I was doing it manually but sorry I didn't explain that I was doing it using a rectangle from obj_control.
I have now moved the logic into an obj_intro which gets called from obj_control room start event (for when you quit back to main menu) as per below code.
Its much nicer having this logic cleaned out of obj_control so thanks for your suggestion :biggrin:


obj_intro (just a fader at this point since I haven't made an intro)
CREATE:
fade_alpha=1;
fade_rate=0.03;
instance_deactivate_all(true);
DRAW:
if (fade_alpha > 0)
{
    draw_set_color(c_black);
    draw_set_alpha(fade_alpha);
    draw_rectangle(0,0,room_width,room_height,false);
    fade_alpha-=fade_rate;
} else {
    instance_destroy();
    instance_activate_all();
}

I don't think you need a variable for the fading rate but unless you plan to manipulate it it is an ok code!Posted Image
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users