unable to correctly disable invisible trigger and block

Need help with using DizzyAGE then look here
User avatar
boo
Hard Boiled Egg
Posts: 142
Joined: Thu Jan 14, 2010 8:55 pm
Location: Norfolk, UK

unable to correctly disable invisible trigger and block

Postby boo » Sun Mar 26, 2017 6:13 pm

I'm having a problem with a piece of coding (may possibly be brushes in the map?) I've been trying to figure this out all afternoon with no success.

My collider call action is:
type - dynamic
id - 2002
material - air
draw - mat
class - action


This seems to work fine...

my block brush is:
type - static
id - 2003
material - block
draw - mat
collider - none
class - none


this seems to work fine too

the platform that is supposed to appear after using the correct object:
type - static
id - 2005
material - block
draw - mat
disable - yes (as it's only supposed to appear after the right item is used
class - none




I am getting an error message when I use the correct item to make the platform appear. Brushes 2002 and 2003 are supposed to be disabled

Can someone take a look at the coding please and tell me where I've gone wrong (either with the coding or the brushes).

Code: Select all

//broken bridge
func CollideObject_2002_1()
{
   Message1(3,3,"THE BRIDGE IS\nBROKEN. I CAN'T\nGET ACROSS.");
   MessagePop();
}

// fix bridge
func UseObject_2002( idx )
{
   if(idx==ObjFind(120))
   {
      Message0(3,8,"DIZZY USES THE\nBRIDGE REPAIR\nKIT TO FIX\nTHE BRIDGE.");
      MessagePop();
      InventorySub(idx);
      ObjSet(ObjFind(2002),O_DISABLE,1);
      ObjSet(ObjFind(2003),O_DISABLE,1);
      ObjSet(ObjFind(2005),O_DISABLE,0);
      return;
   }
   else
   {
      Message1(3,8,"THAT WON'T WORK.");
      MessagePop();
   }
}
I fully intend to...OOOH! Shiny things! :v2_dizzy_eek:
Image

User avatar
Noggin the Nog
Hard Boiled Egg
Posts: 408
Joined: Sun Jul 01, 2012 12:04 am

Re: unable to correctly disable invisible trigger and block

Postby Noggin the Nog » Sun Mar 26, 2017 8:48 pm

Hi Boo,

I think the correct code should be:

Code: Select all

func UseObject_2002( idx )
{
   if(ObjGet(idx,O_ID)==120)
   {
      Message0(3,8,"DIZZY USES THE\nBRIDGE REPAIR\nKIT TO FIX\nTHE BRIDGE.");
      MessagePop();
      InventorySub(idx);
      ObjSet(ObjFind(2002),O_DISABLE,1);
      ObjSet(ObjFind(2003),O_DISABLE,1);
      ObjSet(ObjFind(2005),O_DISABLE,0);
      return;
   }
   else
   {
      Message1(3,8,"THAT WON'T WORK.");
      MessagePop();
   }
}


The corrected line is  if(ObjGet(idx,O_ID)==120)

In general, be mindful of the difference between the object index (usually written as idx) and the object id. The index is the number the machine uses to identify each object, which you never find out. The id is the number you give the object in the editor, if you want to.

In the code above, the idx refers to the index of the object that's just been selected in the inventory. So if(ObjGet(idx,O_ID)==120) means: if object idx has an id of 120, do the stuff in the brackets.

Personally, I always write my code like this:

Code: Select all

idx = ObjFind(100);
ObjSet(idx,O_DISABLE,1);


instead of

Code: Select all

ObjSet( ObjFind(100),O_DISABLE,1);


I think it's less confusing that way. I hope that was helpful. :)

Grandad
Hard Boiled Egg
Posts: 1349
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Re: unable to correctly disable invisible trigger and block

Postby Grandad » Mon Mar 27, 2017 9:21 am

I'm having a problem understanding your response Simon. The blocker 2005 is a static brush, not a dynamic object and I always thought that static objects had to be defined by 'brush' not 'object'.

Also, and if true, is something I never knew. Colliders can be defined with 'UseObject' ? I always thought that colliders were different to action objects and engine wise colliders took precedence over action objects. For colliders I have always added a sub-section if the player is holding a specific item in their inventory.ie

Code: Select all

func CollideObject_2002_1()
{
Message1 (4,3, "\"Oh no, the bridge is broken!\"");
MessagePop();
if (InventoryHasItem(135))
{
Message1 (4,3, "\"Lucky I have the bridge repair kit with me\"");
MessagePop();
ida = ObjFind (135);
idb - ObjFind(2002);
idc = BrushFind(2003);
idd = BrushFind(2005);
InventorySub(ida);
ObjSet(idb, O_DISABLE, 1);
BrushSet(idc, O_MATERIAL, 0);
BrushSet(idd, O_MATERIAL, 7);
BrushSet(idd, O_DRAW, 3);
GameCommand(CMD_REFRESH);
return;
}
return;
}


which would keep the collide Object and 'block' active if the bridge kit wasn't in the inventory. But if you can use a UseObject define on a collider then that would be more in keeping with opening the inventory to choose an item rather than responding to an item held in the inventory ....and something that I will start using in future.

But, I still think that your response would fall over regarding the coding of the static block(s) for the repaired bridge (unless you use a dynamic object with a hard collision property) ..unless there is something else I've never learnt.

Grandad
Hard Boiled Egg
Posts: 1349
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Re: unable to correctly disable invisible trigger and block

Postby Grandad » Mon Mar 27, 2017 10:13 am

Well, cover me in chocolate and call me Charlie! You can use a useobject function on a collider, as long as you define the object as both a collider (call handler, 1) and as an class (action, 1). The collider still has priority, but when I did a test, the collider function operated fine with a mode of 1 (just entering) so that the collider was still in 'Dizzy's touch range' when pressing the return button to open the inventory.

However, I still screwed up on the coding as I used O_DRAW etc rather than B_DRAW etc, so try something like this:
(PS I have no problem using ObjSet(ObjFind as I was trained to touch type and that skill is like riding a bicycle :tup:

Code: Select all

func CollideObject_2002_1()
{
Message1 (4,3, "\"Oh no, the bridge is broken\"");
MessagePop();
}

func UseObject_2002(idx)
{
if (idx == ObjFind(120))
{
InventorySub(idx);
Message1 (4,3, "\"I'll use the bridge repair kit\"");
MessagePop();
ObjSet(ObjFind(2002), O_DISABLE, 1);
BrushSet(BrushFind(2003), B_MATERIAL, 0);
BrushSet(BrushFind(2005), B_DRAW, 3);
BrushSet(BrushFind(2005), B_MATERIAL, 7);
GameCommand(CMD_REFRESH);
return;
}
else
{
DropObject(idx);
}}


That way you'll get the message whenever you collide with object 2002 until you've fixed the bridge and have the ability to open your inventory whilst standing in the collider field.

Personally, I always use some special coding I got from Jamie for block enabling and disabling both seen and invisible and put them in all my 'utility' files so that basically you just have to type 'Makeair(2003) and Enable_Blocker(2005) to remove the first block and enable the bridge without having to do all the extra typing.

User avatar
boo
Hard Boiled Egg
Posts: 142
Joined: Thu Jan 14, 2010 8:55 pm
Location: Norfolk, UK

Re: unable to correctly disable invisible trigger and block

Postby boo » Mon Mar 27, 2017 10:46 am

Thank you, Grandad..that worked perfectly!!!! :D Thank you!!
I fully intend to...OOOH! Shiny things! :v2_dizzy_eek:
Image

User avatar
Noggin the Nog
Hard Boiled Egg
Posts: 408
Joined: Sun Jul 01, 2012 12:04 am

Re: unable to correctly disable invisible trigger and block

Postby Noggin the Nog » Mon Mar 27, 2017 8:59 pm

Grandad wrote:I'm having a problem understanding your response Simon. The blocker 2005 is a static brush, not a dynamic object and I always thought that static objects had to be defined by 'brush' not 'object'.



Apologies. I didn't read the question properly. I was only talking about the line if(idx==ObjFind(120)) which, now I look at it again, would probably work just fine. I've just never written my code that way. :embarassed:

Grandad
Hard Boiled Egg
Posts: 1349
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Re: unable to correctly disable invisible trigger and block

Postby Grandad » Tue Mar 28, 2017 9:04 am

Don't apologise to me Simon. I've learnt something new about colliders. I'm still a total amateur and to be honest a lot of stuff I manage to get working could probably be done a lot easier. I remember your clock coding - I took one look and thought 'I don't understand double-dutch' :v2_dizzy_down: so went back to using the trusted and tried method of a long winded function adding 1 to the status of an invisible object and saying 'do this' whenever the status reached a multiple of say 50 ..which probably would be a lot easier with a counter ...which I know of as being something to do with two plus signs but other than that I haven't a clue.


cron