Jump to content


Photo

Loop Code


  • Please log in to reply
8 replies to this topic

#1 Ford

Ford

    GMC Member

  • New Member
  • 8 posts

Posted 23 December 2007 - 09:48 PM

Good evening and merry Xmas. I'm having troubles setting up parent objects: Let's say I have 2 objects, where obj_item is PARENTAL to obj_sword:

obj_item:
Create event: 
Execute a piece of code:
itemStatus = 0; // determines whether item is dragged(1) or not dragged (0)
+ some step event code

obj_sword:
Create event:
Execute a piece of code:
itemStackType = string("weapon"); // defines a stack type of item (specifies the slot in inventory able to carry this item)

From what I've caught up about parent objects, the children objects should behave like the parents, thus obj_sword should have a variable itemStatus declared, however, this is not happening - when I run the game, a pop-up alert says that itemStatus is not defined.

Note: It only is happening if there's no event in obj_sword, so there basically must be some kind of collision between the inherited create event and the create event in obj_sword. It is not possible to combine these?

Edited by Ford, 28 December 2007 - 03:51 PM.

  • 0

#2 Felix-the-Ghost

Felix-the-Ghost

    GMC Member

  • New Member
  • 81 posts

Posted 23 December 2007 - 10:02 PM

I don't think parent object inherit variables local to them.
Probably set up another local variable :P
  • 0

#3 Zsy

Zsy

    GMC Member

  • New Member
  • 54 posts

Posted 23 December 2007 - 10:03 PM

Good evening and merry Xmas. I'm having troubles setting up parent objects: Let's say I have 2 objects, where obj_item is PARENTAL to obj_sword:

obj_item:

Create event: 
Execute a piece of code:
itemStatus = 0; // determines whether item is dragged(1) or not dragged (0)
+ some step event code

obj_sword:
Create event:
Execute a piece of code:
itemStackType = string("weapon"); // defines a stack type of item (specifies the slot in inventory able to carry this item)

From what I've caught up about parent objects, the children objects should behave like the parents, thus obj_sword should have a variable itemStatus declared, however, this is not happening - when I run the game, a pop-up alert says that itemStatus is not defined.

Note: It only is happening if there's no event in obj_sword, so there basically must be some kind of collision between the inherited create event and the create event in obj_sword. It is not possible to combine these?

<{POST_SNAPBACK}>


Can't you just add the top code into the second object's code?
  • 0

#4 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 24 December 2007 - 05:23 AM

When you have something in an event, it overrides the parent's. So you have to call the parent's one explicitly, putting either event_inherited() or :P.
  • 0

#5 Ford

Ford

    GMC Member

  • New Member
  • 8 posts

Posted 24 December 2007 - 11:34 PM

Another, similar problem showed up:

I want to make a box with item name pop up when I hover the mouse over an item:

obj_item (= parent item of other items like obj_sword etc.):
Step event:
Piece of code:
// popup code
if ((mouse_x >= x-16) && (mouse_x <= x+16) && (mouse_y >= y-16) && (mouse_y <= y+16) && (not mouse_check_button(mb_any)))
 instance_activate_object(obj_popup);
else
 instance_deactivate_object(obj_popup);

obj_popup (= object which draws the rectangle, later to be filled with item name text):
Draw event:
Piece of code:
draw_rectangle_color(mouse_x+8,mouse_y+8,mouse_x+88,mouse_y+24,c_re
d,c_red,c_red,c_red,true);

The problem is, that the rectangle draws only when hovering over the item with highest ID (even though there are no such adressed variables as obj_item.x). I've already tried such things as creating a controller object with global variable showItemDescription (true/false) but it still does the same. Can anyone help me out?
  • 0

#6 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 25 December 2007 - 01:32 AM

The problem is that every instance of obj_item (except the one the mouse cursor is on) deactivates obj_popup. Suppose that there are four items and the mouse cursor is on the third one:
#1 deactivates the popup, then
#2 deactivates the popup, then
#3 activates the popup, then
#4 deactivates the popup.
The last one wins.

You need to rethink other way. Firstly, deactivating an instance to control its visibility isn't a good idea: you can make it invisible by setting the in-built variable visible to false, or just stop drawing it. In case your items has sprite or mask, you can just do:
/* Draw event of popup */
if (position_meeting(mouse_x, mouse_y, obj_item)) {
    draw_rectangle_color(bla bla bla);
}
In case they have no sprite, you'd better let another object to control the visibility of popup, e.g.:
/* Step event of controller */
obj_popup.visible = false;
if (mouse_check_button(mb_any)) {
    with (obj_item) {
        if ((mouse_x >= x-16) && (mouse_x <= x+16) && (mouse_y >= y-16) && (mouse_y <= y+16)) {
            obj_popup.visible = true;
            break;
        }
    }
}

  • 0

#7 drt_t1gg3r

drt_t1gg3r

    GMC Member

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

Posted 25 December 2007 - 02:39 AM

in each item object
my_popup=what ever it's popup is;

in parental mouse enter event
drw_popup=true;

in parental mouse exit event
drw_popup=false;

in parental draw event
if(drw_popup)
{
draw_rectangle(blah,blah,blah);
instance_activate(my_popup);
}
else
instance_deactivate(my_popup);
  • 0

#8 Ford

Ford

    GMC Member

  • New Member
  • 8 posts

Posted 25 December 2007 - 02:18 PM

I've got the point, thank both of you.
  • 0

#9 Ford

Ford

    GMC Member

  • New Member
  • 8 posts

Posted 28 December 2007 - 02:59 PM

I'm very sorry but I'm struggling over the same problem over 3 days so I decided to post whole *.GM6 file here.

HERE was a download link.

What's the problem: For some weird reason I can't get the items dropped into proper slots. SEE Global Left Button event in OBJ_ITEM.

SOLVED myself, right after I pressed "Submit Modified Post", I found the code mistake, how typical of me..

Edited by Ford, 28 December 2007 - 03:59 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users