View Full Version : Can't get object status to change
Grandad
15-10-09, 12:30 PM
I hope this isn't a silly query, and I'm not missing anything obvious. As you can see from the coding Player A has an action response and then switches to a use object response. This works fine. personB has an action response that is different if the player hasn't spoken to PersonA first ...and then they should switch to a use object response.The conversations work fine, but I can't get PersonB to move to a use object response. I just keep getting the status 1 response.
func ActionObject_548(idx) // personA
{
if(ObjGet(ObjFind(548), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGE\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 1); //personB
ObjSet(ObjFind(548), O_STATUS, 1); //personA
}
else
{
idx = OpenDialogInventory();
if (idx!=-1) // have items in inventory
{
UseObject(idx);
}
}
}
func ActionObject_554(idx) // personB
{
if(ObjGet(ObjFind(554), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGEA\"");
MessagePop();
}
else
if(ObjGet(ObjFind(554), O_STATUS) == 1)
{
Message2 (6,4, "\"MESSAGEB\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 2);
}
else
{
idx = OpenDialogInventory();
if (idx!=-1);
{
UseObject(idx);
}
}
}
Also, later on I'm going to try for a use two items first to make a third item respond. Is there a way to advance a status, ie add 1, rather then set the status to a number, which I seem to think is what the set status does. If not, is it possible to set two 'non-related' action blocks to a status of 1 for each item correctly used and then use a && command to check that the status of both 'blocks' is 1, for example:
idx1 = ObjFind(1000);
idx2 = ObjFind(1001);
if ((if (ObjGet(idx1, O_STATUS) ==1)) && (if (ObjGet(idx2, O_Status) == 1)))
(would you need the 'strap' to enclose both?) ...my brain hurts!
Grandad
I hope this isn't a silly query, and I'm not missing anything obvious. As you can see from the coding Player A has an action response and then switches to a use object response. This works fine. personB has an action response that is different if the player hasn't spoken to PersonA first ...and then they should switch to a use object response.The conversations work fine, but I can't get PersonB to move to a use object response. I just keep getting the status 1 response.
func ActionObject_548(idx) // personA
{
if(ObjGet(ObjFind(548), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGE\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 1); //personB
ObjSet(ObjFind(548), O_STATUS, 1); //personA
}
else
{
idx = OpenDialogInventory();
if (idx!=-1) // have items in inventory
{
UseObject(idx);
}
}
}
func ActionObject_554(idx) // personB
{
if(ObjGet(ObjFind(554), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGEA\"");
MessagePop();
}
else
if(ObjGet(ObjFind(554), O_STATUS) == 1)
{
Message2 (6,4, "\"MESSAGEB\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 2);
}
else
{
idx = OpenDialogInventory();
if (idx!=-1);
{
UseObject(idx);
}
}
}
Also, later on I'm going to try for a use two items first to make a third item respond. Is there a way to advance a status, ie add 1, rather then set the status to a number, which I seem to think is what the set status does. If not, is it possible to set two 'non-related' action blocks to a status of 1 for each item correctly used and then use a && command to check that the status of both 'blocks' is 1, for example:
idx1 = ObjFind(1000);
idx2 = ObjFind(1001);
if ((if (ObjGet(idx1, O_STATUS) ==1)) && (if (ObjGet(idx2, O_Status) == 1)))
(would you need the 'strap' to enclose both?) ...my brain hurts!
Grandad
first of all, i see no reason off the top of my head why your code shouldn't work. The only possible issues are that you're using a lot of 'else' statements, which i try to steer clear of.
EDIT:: i just noticed you have a semi-colon ( ; ) after an 'if' statement on the person B object switch
Personally i'd code it like this:
func ActionObject_548(idx) // personA
{
if(ObjGet(ObjFind(548), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGE\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 1); //personB
ObjSet(ObjFind(548), O_STATUS, 1); //personA
return; //stops the function once finished
}
if(ObjGet(ObjFind(548), O_STATUS) == 1)
{
idx = OpenDialogInventory();
if (idx!=-1) { UseObject(idx); }
}
}
func ActionObject_554(idx) // personB
{
if(ObjGet(ObjFind(554), O_STATUS) == 0)
{
Message2 (6,4, "\"MESSAGEA\"");
MessagePop();
return; //stops the function once finished
}
if(ObjGet(ObjFind(554), O_STATUS) == 1)
{
Message2 (6,4, "\"MESSAGEB\"");
MessagePop();
ObjSet(ObjFind(554), O_STATUS, 2);
return; //stops the function once finished
}
if(ObjGet(ObjFind(554), O_STATUS) >= 2) //if status is greater or equal to 2
{
idx = OpenDialogInventory();
if (idx!=-1) { UseObject(idx); }
}
}
I would expect that to work. I'm not sure where the difference between your and mine is, that stops yours from working though.
secondly, the way to advance an object status is thus:
idx = ObjFind(554)
ObjSet(idx,O_STATUS,ObjGet(idx,O_STATUS)+1);
and the way to set multiple checks is thus:
idx1 = ObjFind(1000);
idx2 = ObjFind(1001);
if(ObjGet(idx1,O_STATUS)==1&&ObjGet(idx2,O_STATUS)==1)
I hope this helps.
Hi !
I've tried your Action code and it works fine for me. Only remove the semi-colon ( ; ) as delta said. Because when you'll hit ESC in inventory you'll get an error message because of the wrong index (-1).
But as I said, after conversation I receive an inventory dialog. Very strange why you don't.
But for sure use code constructions as delta wrote.
Grandad
16-10-09, 10:22 AM
Thanks Guys. I think I'll use your code to be safe as I was using the 'giving items to Dylan in Mushroom Pie' as a basic template, and thanks for the info on status upgrading and multiple checks - it will prove to be very useful.
By the way Jamie, I've also found your 'ReplaceInventoryItem' code, which is rather superb as in one part of my game I want to include a 'magic chest' that changes an inventory item into another item. I've already tested it for another puzzle and it works fine ...when I remembered to place the new item in an empty room.
Oh well, back to another whole day typing in coding, dealing with all the basic typing errors ...and then checking it again when the game falls over! (I'm loving it really)
Thanks again
Grandad
xelanoimis
16-10-09, 08:40 PM
idx = OpenDialogInventory();
if (idx!=-1); // this ; was the problem
{
UseObject(idx); // this is always executed
}
using the ; after an if statement means that if the condition is true it will do just nothing. and the next call to UseObject will be executed no mater what the if condition is. Obviously when ESC was pressed the idx was -1 and that wasn't accepted in the UseObject.
Using "else" with if instructions is perfectly fine too.
Alex
Using "else" with if instructions is perfectly fine too.
oh yeah i know in most cases it will be fine. I just personally don't like doing it, mainly cause using them with 'if' statements can confuse me a bit!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.