DizzyAGE General Coding Queries
Started by delta on 9 February 2008 • 258,915 views
The only thing I can think of is that the 'targets' are not done correctly. Try setting the 'moving object' to a status of 1 to ensure that it does start moving when you enter the room.
What I had in mind to use it for was to make a lift move up and down when the player was standing in a certain spot with a certain object in the inventory. But even though I had the lift and waypoints set up correctly the darn thing wouldn't move! So I got rid of all the code and tried to figure out what might be causing the problem by starting again with a "clean" lift. But then, for some bizarre reason, I couldn't even get THAT to work!
So I gave up, and now the lift is just sitting there on the map, made of air and with no ID, waiting until I've finished doing other things!
Which leads us to the other problem you helped me with! I've incorporated what you suggested into my map and scripts:
func UseObject_66(idx)
{
if (idx == ObjFind(1007))
{
InventorySub(idx);
Message1(4,3,""HERE'S YOUR GLASSES,nGRAND DIZZY."");
Message2(5,4,""THANKS, DIZZY."");
MessagePop();
ObjSet(idx,O_STATUS,1);
idx = ObjFind(2000);
ObjSet(idx, O_STATUS, ObjGet(idx, O_STATUS) +1);
if (ObjGet(idx, O_STATUS) == 2)
{
grand = ObjFind(66);
ObjSet(grand,O_STATUS,ObjGet(grand,O_STATUS)+1);
if (ObjGet(idx, O_STATUS) == 3)
{
Message2(4,3,""OH, DIZZY. WHATnARE WE GOING TOnDO? THE TREASURESnOF ZEFFAR HAVEnBEEN STOLEN..."");
Message2(5,4,""...IT HAS BEENnFORETOLD THAT IFnTHIS SHOULD EVERnHAPPEN, AN EVILnCURSE WOULD BE CASTnACROSS THE LAND."");
Message2(6,5,""YOU'VE GOT TO HELP!"");
Message1(4,3,""WHAT MUST I DO?"");
Message2(5,4,""YOU MUST FIND THEnTREASURES ANDnRETURN THEM TOnTHE SACRED SHRINE."");
Message2(6,5,""TAKE THIS SCYTHE TOnHELP GET YOU THROUGHnTHE THORNS BY THEnPOWER SUPPLY HUT."");
Message2(7,6,""GOOD LUCK, DIZZY."");
MessagePop();
idx = ObjFind(1011);
ObjSet (idx,O_DISABLE,0);
return;
}
return;
}
if (idx == ObjFind(1010))
{
InventorySub(idx);
Message1(4,3,""HERE'S THE NEWSPAPER,nGRAND DIZZY."");
Message2(5,4,""THANKS, DIZZY."");
MessagePop();
ObjSet(idx,O_STATUS,1);
idx = ObjFind(2000);
ObjSet(idx, O_STATUS, ObjGet(idx, O_STATUS) +1);
if (ObjGet(idx, O_STATUS) == 2)
{
grand = ObjFind(66);
ObjSet(grand,O_STATUS,ObjGet(grand,O_STATUS)+1);
if (ObjGet(idx, O_STATUS) == 3)
{
Message2(4,3,""OH, DIZZY. WHATnARE WE GOING TOnDO? THE TREASURESnOF ZEFFAR HAVEnBEEN STOLEN..."");
Message2(5,4,""...IT HAS BEENnFORETOLD THAT IFnTHIS SHOULD EVERnHAPPEN, AN EVILnCURSE WOULD BE CASTnACROSS THE LAND."");
Message2(6,5,""YOU'VE GOT TO HELP!"");
Message1(4,3,""WHAT MUST I DO?"");
Message2(5,4,""YOU MUST FIND THEnTREASURES ANDnRETURN THEM TOnTHE SACRED SHRINE."");
Message2(6,5,""TAKE THIS SCYTHE TOnHELP GET YOU THROUGHnTHE THORNS BY THEnPOWER SUPPLY HUT."");
Message2(7,6,""GOOD LUCK, DIZZY."");
MessagePop();
idx = ObjFind(1011);
ObjSet (idx,O_DISABLE,0);
return;
}
return;
}
else
{
DropObject(idx);
}
}
But I can't even check if it works because I get a parse error message for the line below the last line of that new code. I've used what you gave me and triple checked the new stuff I put in, it sure looks like it's correct to me but obviously something is wrong somewhere!
You've got the invisible checker with id 2000
grand dizzy with id 66
the two items with id's of 1010 and 1007
the new item grand dizzy gives you after the dialogue with an id of 1011.
If you've the time could you check through this, if it's a parse error nine times out of ten it's usually down to one of these {} being misplaced. At this point I'm blind to it :tongue:
Ok, it looks like you're going round the houses with this Pogie.The syntax is wrong cos you haven't closed the first item check as there are two 'if' statements to close - need to add another } after first return - should always be just one } left after each item check. But, you don't need to change the status of the specs and paper when you give them to GDizzy, or update his status as obj 2000 takes care of that. Try doing it this way:
func ActionObject_66()
{
idx = ObjFind(66);
if (ObjGet (idx, O_STATUS) == 0)
{
add the initial conversation with G'Dizzy
ObjSet(idx, O_STATUS, 1);
return;
}
if (ObjGet(idx, O_STATUS) == 2)
{
add message about the stolen treasures
ObjSet(ObjFind(1011), O_DISABLE, 0);
ObjSet(idx, O_STATUS, 3);
return;
}
if (ObjGet(idx, O_STATUS) == 3)
{
add message about getting on with the search
return;
}
if (ObjGet(idx, O_STATUS) == 1)
{
idx = OpenDialogInventory();
if (idx!=-1) {UseObject(idx);}
}
}
func UseObject_66(idx)
{
if (idx == ObjFind(1007))
{
InventorySub(idx);
add message about specs
idx = ObjFind(2000);
ObjSet(idx, O_STATUS, ObjGet(idx, O_STATUS) +1)
if (ObjGet(idx, O_STATUS) == 2)
{
ObjSet(ObjFind(66), O_STATUS, 2) //sets GDizzy to 2 when actioning him as has both items
return; // closes 2000 'if' statement
}
return; // closes 'given specs' if first item given
}
if (idx == ObjFind(1010))
{
InventorySub(idx);
add message about paper
idx = ObjFind(2000);
ObjSet(idx, O_STATUS, ObjGet(idx, O_STATUS) +1)
if (ObjGet(idx, O_STATUS) == 2)
{
ObjSet((ObjFind(66), O_STATUS, 2);
return; //closes 2000 if statement
}
return; //closes 1010 if first item given
}
else
{
DropObject(idx);
}
}
NB - using ObjGet(ObjFind(xxx) is sometimes easier than continually switching objects to be idx if there are a lot of objects involved in the function.
Moving the lift by standing in a 'colllider' is basically what I used in The Sisterhood - if you've downloaded it check out the 'boulders.gs' file. Obj 423 is the 'beam' that the girls use to move the lift up and down (obj 421) ...room 8_3.
Sometimes when 'moving' objects don't work I've found that I've accidentally used the id number previously in bits of ground etc that are set as hard contact objects so you can't drop an item. A good check is often to just use new id numbers for the lift and targets that you know haven't been used yet.
Set the 'new' lift with a status of '1' to check that it does move up and down when entering the room with the 'UpdateRoom' function. Once you've got it working then just add the collider (mode 2) ...and switch the lift's status to zero:
func CollideObject_423_2()
{
if (PlayerGet(P_TILE) == 10 && InventoryHasItem(xxxx))
{
ObjSet(ObjFind(421), O_STATUS, 1);
}
if (PlayerGet(P_TILE) == 40 && InventoryHasItem(xxxx)) //if wearing scuba
{
ObjSet(ObjFind(421), O_STATUS, 1);
}
if (PlayerGet(P_TILE) != 10) // no need to check for inventory item
{
ObjSet(ObjFind(421), O_STATUS, 0);
}
if (PlayerGet(P_TILE, !=40)
{
ObjSet(ObjFind(421), O_STATUS, 0);
}
}
You could use:
if (PlayerGet(P_TILE) == 10 || PlayerGet(P_TILE) == 40 && InventoryHasItem(xxxx))
as a shorter version ie if Diz_Idle or DizAqua_idle and has inventoryitem, but I've sometimes found that the engine plays silly buggers when using 'or' with 'and' statements, so tend to them separately.
Hope this helps.
It does help, thank you so much Grandad! I was getting myself all twisted into knots but I can see how to make this whole thing work now. Big thanks {yolkfolk}:clap:
But, and I swear this isn't down to my usual amateurishness, something rather odd is happening with the lifts...
I couldn't get any movement whatsoever. I started again with fresh tiles for everything. Then put in the id's and classes and everything just as it should be. But it still wouldn't move. There is no extraneous code anywhere and the id numbers were changed several times just in case, but nothing. Having given up totally I was playing through another part of the game that had the same functions using waypoints and was activated by dropping an object and THAT has stopped working too! It worked just fine and it's never gone wrong before and I haven't touch the tiles or code for that puzzle for months.
Has anything like this happened to anyone else and more importantly how on earth can I go about "fixing" it?!
Btw, every other moving object in the game, including one in the same room as the lift was meant to be, are moving just fine (although they aren't using waypoints.) I generally don't monkey around with any code outside of game.gs and when I do I'm extremely careful.
I'm hugely confused :surprise:
I know with me it's usually that I've forgotten to include GameCommand(CMD_REFRESH) after trying to move static brushes. I've done that like 10 times and been confused for ages every time. Also, what I've found helpful is to check the tile ID and search the map for duplicates. Often I've accidentally made a few random bushes or something 10 screens away with the same ID. And once or twice, I've just cut the code, played the program, pasted it back in and tried again to get it working. It can be temperamental... but I still love it :teethy:
If you're really stuck, I'd be happy to have a look at the game for you. Do you use Dropbox?
Those two properties are preset in the AI.gs file and shouldn't cause a problem unless you've added 32 as a different user variable at the bottom of the def.gs file.
Other than that, as long as the 'moving' object and all targets are dynamic (and ID numbers correctly typed) and the moving object gets a status of '1' and the moving object ID is the one used for the AI function in the UpdateRoom function then the only other problem is generally a duplicate ID. Another way to check is to test the AI function by giving the objects concerned ridiculously high numbers such as 20000 to ensure that you haven't accidentally mistyped any id numbers.
Or you could zip up the game and give it to Simon via Dropbox (easy to download, but tends to want to shift all your saved files to Dropbox for a while).
Thanks guys, I've made a post in the Crystal Kingdom thread that addresses some of my earlier posts here. Didn't want to clog up this thread!
I do have one small question that hopefully has a simple answer but it's something I just can't figure out.
How do I get the game to check if there are TWO items in the inventory when solving a puzzle? I've got this code:
/////////////////////////////////////////////////////////////////////////////////
//Leaky Hull
/////////////////////////////////////////////////////////////////////////////////
func ActionObject_108()
{
idx = OpenDialogInventory();
if(idx!=-1) UseObject(idx);
}
func UseObject_108( idx )
{
if(ObjGet(idx,O_ID)==1019)
if(InventoryHasItem(1015))
{
InventorySub(idx);
idx = ObjFind(1015);
InventorySub(idx);
idx = ObjFind(1017);
InventorySub(idx);
Message0(4,3,"YOU CUT THE PLANKnTO THE CORRECTnSIZE AND PLACE ITnOVER THE LEAK.");
Message0(5,4,"THE STICKY TAPEnHOLDS THE PLANKnFIRMLY IN PLACE.");
Message0(6,5,"THE LEAK IS REPAIRED!");
MessagePop();
idx = ObjFind(109);
ObjSet (idx,O_DISABLE,1);
pirate = ObjFind(85);
ObjSet(pirate,O_STATUS,ObjGet(pirate,O_STATUS)+1);
}
else
{
DropObject(idx);
}
}
It requires the player to USE object 1019 (the plank of wood) but be holding object 1015 (the sticky tape) AND object 1017 (the saw). I thought a simple || between the two ids in the ifinventoryhasitem part would suffice but nope! It's tiny but it does matter.
Any help would be gratefully received!
|| means OR, maybe try && for AND, if you want to test for holding both.
func UseObject_108(idx)
{
if (idx == ObjFind(1019) && InventoryHasItem(1015) && InventoryHasItem(1017))
{
InventorySub(idx);
idx = ObjFind(1015);
InventorySub(idx);
idx = ObjFind(1017);
InventorySub(idx);
Blah blah blah, leak fixed
disable 109
add 1 to pirate status
return;
}
else
{
DropObject(idx);
}
}@Grandad, can I ask for your help with the above code yet again?! It works just fine on its own terms but there is more needed and try as I might I just can't insert anything new into it without it shaking its head at me and tutting.
What's required is for grand dizzy to give you a message every time you action him AFTER you've given him both the items. It recurs until another puzzle increases his status so that he displays the final messages and gives dizzy the scythe. Where I'm getting into trouble is that the other puzzle can be solved at ANY time before or after the specs and paper are available.
If that made sense I'd really appreciate some assistance, coding this puzzle has been nothing but trouble since the beginning and I'll be glad to see the back of it! {dizzy}:mad:
if (ObjGet(idx, O_STATUS) == 2 && ObjGet(ObjFind(xxxx), O_STATUS) == 1)
{
give scythe etc
set GDizzy status 3
return;
}
if (ObjGet(idx, O_STATUS) == 2)
{
give message after getting specs and glasses
return;
}
I've added a status change (which you needn't code) so that Gdizzy doesn't attempt to give the scythe again when you next action him.
Well Grandad I tried that and with all my usual skill I managed to make it not work. However, somewhere in amongst my head scratching inspiration struck me and I've miraculously got it working PRECISELY how it should. Thank you for your help, I would never have gotten to this point without you - and I know a little more than I did before too, even if it's what NOT to do! {yolkfolk}:bigwink:
Glad you've got it working Pogie, but never worry about doing things the 'proper' way as long as what you've done works. Most experienced programmers would take a look at my general coding and go 'tut tut' at some of my long winded efforts to make something work ..and I still have no idea what 'fid' means. {yolkfolk}:scratch:
Okay, so I'm attempting to code a bat that is hanging from the roof of a room to drop down when the player hits a collider, change into a flying bat tile and fly toward the player. Once the player exits the room everything should be reset to how it was before the player hit the collider.
As it stands, the first time the player hits the collider the hanging bat falls to its waypoint, transforms into the flying bat but does not move toward the player. Instead it hovers on the spot only moving up a few pixels if Dizzy is higher than where it is on the screen (and it'll only do that a couple of times before not moving at all.) When Dizzy exits and re-enters the room the hanging bat is back on the ceiling and the flying bat is gone but when the player hits the collider the hanging bat disappears straight away and then the flying bat appears a few seconds after that, once again not really moving anywhere!
I was quite sure that I'd kept everything simple enough codewise for me to identify any problems fairly easily but this just isn't working. I have a suspicion it might be to do with the waypoint because the hanging bat's target is set to go to the waypoint but that waypoint doesn't send it anywhere else. Maybe that's not it at all and the whole thing is fundamentally flawed and it was just blind luck any part of it worked! Do please have a gander and let me know your thoughts guys :smile:
I've set:
Collider id - 12345
Hanging bat id - 5678
Flying bat id 5679
/////////////////////////////////////////////////////////////////////////////////
//Nasty Bats
/////////////////////////////////////////////////////////////////////////////////
func CollideObject_12345_1()
{
{
idx = ObjFind(12345);
ObjSet (idx,O_DISABLE,1);
idx = ObjFind(5678);
ObjSet (idx,O_X,26);
ObjSet (idx,O_Y,421);
ObjSet (idx,O_STATUS,1);
WaitFrames(65);
ObjSet (idx,O_DISABLE,1);
idx = ObjFind(5679);
ObjSet (idx,O_DISABLE,0);
ObjSet (idx,O_X,26);
ObjSet (idx,O_Y,509);
y = ObjGet(idx,O_Y);
x = ObjGet(idx,O_ X) ;
py = PlayerGet(P_Y);
px = PlayerGet(P_ X) ;
if(y < py) { y+=2; ObjSet(idx,O_Y,y); } if(y > py)
{
y-=2;
ObjSet(idx,O_Y,y);
}
if(x < px) { x+=2; ObjSet(idx,O_X,x); } if(x > px)
{
x-=2;
ObjSet(idx,O_X,x);
}
}
}
func UpdateRoom_0_3()
{
AIUpdateTrain(ObjFind(5678));
ObjPresent(ObjFind(5678));
AIUpdateTrain(ObjFind(5679));
ObjPresent(ObjFind(5679));
}
func CloseRoom_0_3()
{
idx = ObjFind(5678);
ObjSet (idx,O_DISABLE,0);
ObjSet (idx,O_X,26);
ObjSet (idx,O_Y,421);
ObjSet (idx,O_STATUS,0);
idx = ObjFind(5679);
ObjSet (idx,O_DISABLE,1);
idx = ObjFind(12345);
ObjSet (idx,O_DISABLE,0);
}My comments in the other thread about the bat were about using specific functions not AI. You can't adjust the movement or speed with AI except by adjusting the properties of the waypoints. Also if you want AI to repeat a movement you also have to reset the initial targets.
If (as I've seen in the video) the bat drops to a fixed point then moves left or right in a straight line out of the room then you can use AI. I'd suggest using two flying bats (one for each direction) and making a check of Dizzy's 'x' position after the drop, at the end of the WaitFrames(65) command to determine which bat to enable.
collider = 100
dropping bat = 101 pos 1000, 1000
target = 102 pos 1000, 1050
left flying bat = 103, pos 1000, 1050
target = 104 pos 800, 1050
right flying bat = 105, pos 1000, 1050
target = 106 pos 1200, 1050
func CollideObject_100_1()
{
ida = ObjFind(100);
idb = ObjFind(101);
idc = ObjFind(103);
idd = ObjFind(105);
ObjSet(ida, O_DISABLE, 1);
ObjSet(idb, O_STATUS, 1);
WaitFrames(65);
ObjSet(idb, O_DISABLE, 1);
ObjSet(idb, O_STATUS, 0);
px = PlayerGet(P_ X) ;
x = ObjGet(idb, O_ X) ;
if (x < px) { ObjSet(idd, O_DISABLE, 0); ObjSet(idd, O_STATUS, 1); } if (x > px)
{
ObjSet(idc, O_DISABLE, 0);
ObjSet(idc, O_STATUS, 1);
}
ObjSet(idb, O_Y, 1000);
}
func CloseRoom_xx_xx()
{
ObjSet(ObjFind(100), DISABLE, 0);
idb = ObjFind(101);
ObjSet(idb, O_DISABLE, 0);
ObjSet(idb, O_TARGET, 102);
idc = ObjFind(103);
ObjSet(idc, O_DISABLE, 1);
ObjSet(idc, O_STATUS, 0);
ObjSet(idc, O_X, 1000);
ObjSet(idc, O_TARGET, 104);
idd = ObjFind(105);
ObjSet(idd, O_DISABLE, 1);
ObjSet(idd, O_STATUS, 0);
ObjSet(idd, O_X, 1000);
ObjSet(idd, O_TARGET, 106);
}
func UpdateRoom_xx_xx()
{
idx = ObjFind(101);
AIUpdateTrain(idx);
idx = ObjFind(103);
AIUpdateTrain(idx);
idx = ObjFind(105);
AIUpdateTrain(idx();
}
Note that this coding is only for the bat dropping straight down and then flying straight left or right. Also, you don't need to set 'waypoints' as waypoints in the properties just make sure they're active, dynamic, invisible and have the speed property set. I haven't tested it, so hope I haven't missed anything.
Thanks Grandad, I'll have a play around with that and see what happens.
It should be noted that only one of the four bats needs to move either left or right. The other three will have no option but to fly in a set direction because there is only one way into their rooms.
Great stuff though, I appreciate your input {dizzy}:biggrin:
Edit: I've actually solved the problem and can now code the bats to move exactly as they should. I haven't used anything terribly complicated and poor Grandad might keel over when he sees how I've coded this but I've done it. It works, it resets, it works again - there's probably far easier and more elegant ways to do it but from a players point of view the bat drops down and moves toward them.
I can stop tearing my hair out now :smile:
Edit Edit: Yep, so it's all gone horribly wrong, it just doesn't work. I'm no better off now than I was earlier this afternoon! I just haven't got the coding skill to understand how to create the solution :sad: