How to create a function to get objects into solid state.

Started by RyeGuy83, Tue 30/08/2011 21:59:52

Previous topic - Next topic

RyeGuy83

I'm trying to  (A) make objects in my game solid.  and (B) Create a function that can set multiple objects to solid.

For Example:

Table.Solid = true;   (This is what wiki said but didn't work)

Function makeSolid(object)
{
    object.solid = true;
}

so I can just call:

   makeSolid(Table);  (This will call the table.solid = true; function)

Please help ASAP. 

NsMn

Apparently you want it in the "object.Function()" form. In this case, you'd have to put it like this:

Code: ags

void makeSolid(Object this*)
{
    this.solid = true;
}

RyeGuy83

I got this error using that code:


Failed to save room room1.crm; details below
room1.asc(2): Error (line 2): struct cannot be passed as parameter


tried changing Object (which is a struct) to object

then got this error:


Failed to save room room1.crm; details below
room1.asc(2): Error (line 2): PE03: Parse error at 'object'

Khris

The function should look like this:

Code: ags
void makeSolid(this Object*)
{
    this.Solid = true;
}


Plus, you need this in global.ash to make it work in room scripts:

Code: ags
import void makeSolid(this Object*);


But, since the function only contains one simple line, what's the point?

Code: ags
Table.Solid = true;


should work, provided that the Object is called "Table", not "oTable" or "table", and provided that you've put this line into a function, not directly into the room script.
The first hint is that the all-knowing auto-complete window won't suggest "Table" as soon as you've typed "Tab" or "tab".

Also note that in the global script, you have to use the object array instead:

Code: ags
  if (player.Room == 8) object[3].Solid = true;


Now a function for turning multiple objects solid would look like this:

Code: ags
void AllObjectsSolid(bool solid) {
  int i = 0;
  while (i < Room.ObjectCount) {
    object[i].Solid = solid;
  }
}

RyeGuy83

Can someone clear this up a bit?  Still having issues getting my objects to be solid.  I've tried all methods on here, but it still isn't working and the way he worded it is kinda confusing. 

pcj

What errors are you getting?  Please be specific how it's not working.  He was pretty specific on what you need to do so it's hard to elaborate further.
Space Quest: Vohaul Strikes Back is now available to download!

Khris

What exactly is confusing (you)?

And yeah, "isn't working" is not enough.

monkey0506

Are you sure that what you actually mean is "solid" and not, say, "clickable" or "visible"? The solid property is used to make it so that other characters and objects cannot directly move through an object, and will instead move around it when using the Move function (and also the Walk function for characters, which have both functions).

I have a feeling that this is probably not even the property that you're wanting to use. The Clickable property is used to set whether or not the user can click on the object to interact with it, and the Visible property is used to set whether or not you can see the object in the room.

I'm not sure if you would, but you also shouldn't think that this would be in any way related to the Transparency property...because it's not.

RyeGuy83

It just doesn't work at all.  I am trying to do the item.solid = true; function. 

I have tried everything he suggested and I can't get it set so my character can't walk through the couch.  The couch name is oCouch, and has Item ID = 0.  All of our objects are set as oItemName to help clarify the variable as an object.  If I can get one object to work, I should be able to figure out how to do all the rest of them.  Just wasn't clear as to how he said what code to put where.  Some were room script references, while others were .ash references (header file). 

pcj

So, the code to make the couch solid is:

Code: ags
oCouch.Solid = true;


You don't need a special function or anything to set a property.  Just put it in the room_load function or wherever you want to do it.

Also note that ".Solid" is capitalized as written.
Space Quest: Vohaul Strikes Back is now available to download!

Mazoliin

If you are indeed doing oWhatEver.Solid = true, try changing the BlockingHeight and BlockingWidth properties of the object. These defines the size of the area that the object is blocking, and if the couch is a large object, you probably only need to increase those.

RyeGuy83

I currently have this in the room script:

function room_AfterFadeIn()
{
 oCouch.Solid = true;
 oCouch.BlockingHeight = 160;
 oCouch.BlockingWidth = 400;
}

The character can still walk through the couch.

monkey0506

Are any of those properties being changed elsewhere?

You should also check player.Solid, player.BlockingWidth, and player.BlockingHeight, and maybe just for good measure toss something along these lines into your room_RepExec function (make sure you have it linked properly through the room Events pane):

Code: ags
  if (player.IsCollidingWithObject(oCouch)) Display("osolid: %d, psolid: %d, obw: %d, obh: %d, pbw: %d, pbh: %d", oCouch.Solid, player.Solid, oCouch.BlockingWidth, oCouch.BlockingHeight, player.BlockingWidth, player.BlockingHeight);


Oh, and also, checking that your room_AfterFadein event is linked in the room Events pane is probably relevant. You can make sure that it's being called by using a Display statement (or AbortGame! :D). If that command isn't ever called then none of them in the function are, which means that you just created the function in the script without linking it through the events pane.

In case you're not sure what Events pane I'm talking about, if you click the lightning bolt icon above the Properties pane, then you should see it.

RyeGuy83

I used your error checking.  It worked.  But it turns out that the issue was that the character was starting out in the room within the bounds of the object, so it would walk through it.  I had to move away from the object, then back towards it for it to actually collide.

monkey0506

Well you were setting it visible after he was already standing inside of it then, weren't you?

SMF spam blocked by CleanTalk