Checking for time and stack object stuff
#1 29-02-2016 
Hello. I'm back again with questions on internal bits of BHAVs, and I decided to make a new thread this time, since I feel the old one got a bit confusing at this point. I have two questions, but I'll start with one and I'll get to the second one later, to make it a bit less confusing.

I have been experimenting with mods that regulate autonomy based on time, only allowing certain interactions during certain times of day. For this I am using an expression, set up like this (<, >, == and so on based on what I want)
[Image: jhyk9i.png]
While it in itself works like I expect it to, the BHAV is not running like I expect it to. For some reason, when using time checks, it reads the entire thing and applies all of it. By that I mean that if you have more than one condition, it'll always apply the lowest thing you set. I am currently working on sleep autonomy, trying to set energy checks so that Sims can only go to bed autonomously if they sufficiently tired to merit going to bed at that time of day. However, even though it does a time check and only goes to the energy check if the time check came back true, and none of the time checks overlaps, it will apply the lowest energy requirement to all times of day. It's as if it reads everything, and applies everything, even if it wasn't told to go to that line. I've had this happen in the past, but only with time checks, nothing else. I tried putting the time checks in separate bhavs, and calling the bhavs instead, as well as copying the format of the global day/night time checks, but it still reads all of it.

I'm sure there is some kind of reasonable explanation as to why it's doing that. I'd show a screenshot of the code, but unfortunately I don't have access to it right now. What am I missing? Why is it applying an energy check with a time check that's returning false and should be leading to a new line? I've seen someone else have more than one time check in their code, and I noticed they used local and literal. Made me wonder if my problems are because I'm using literal for everything.
gummilutt, proud to be a member of LeeFish since Jun 2013.

0
#2 01-03-2016 
If you have multiple windows in time where certain stuff should happen, you should run those windows in the exact order in wich they occur. And you NEED to test for both the start and the end time of each window to make sure that they are executed in an orderly fashion.

For example, you have three different energy levels: one for the period from 1800 to 2000, one for 2000 to 2200, and one for 2200 to 2400. You must then test in the following order:

0. Global Hour >= 0x12 (True -> 1, False -> 9)
1. Global Hour < 0x14 (True -> 2, False -> 3)
2. Test sim's energy check for this window (True -> 8, False -> 9)
3. Global Hour >= 0x14 (True -> 4, False -> 9)
4. Global Hour < 0x16 (True ->5, False ->6)
5. Test sim's energy check for this window (True -> 8, False -> 9)
6. Global Hour >= 0x16 (True -> 7, False -> 9)
(there is no test for midnight, becasue time resets to 00 anyway)
7. Test sim's energy check for this window (True -> 8, False -> 9)
8. Send sim to bed.
9. Window for sending sims to bed has passed, so have them drink coffee instead.

If you wish to test times past midnight, remember that midnight is 00 the next day. So perform those test first.

One *could* put tests out of order, but it's much easier to mess that up. So do yourself a favor, and keep things ordered chronologically.
Also, some tests *could* be ommitted (for example: testing for ">= 0x14" is not really needed if you've already tested for "< 0x14") but just to make it easier for yourself and others to read, keep those tests in, anyway. At least until you're absolutely certain that everything works as intended (rigorous testing is recommended). Then later, you can always remove the superfluous tests...

1
#3 01-03-2016 
I believe that's how I did it, but I'm not 100% certain, so I'll try again and get back with results Smile Thank you!

0
#4 01-03-2016 
Perhaps you could show us a screenshot of that part of the BHAV then? Maybe I see something that you overlooked.

1
#5 01-03-2016 
Turns out I had not done them in the order 00-23, but rather evening things first and then night things. I re-did them, starting with midnight and then working my way up, and this time it works. I still don't understand why order matters, since I had defined upper and lower limit for each in the previous attempt, but I suppose I must have made a mistake somewhere. I'll stick to this method and it should work Smile Thanks a bunch BO. This had me quite confused.

As information to anyone wanting to attempt this themselves, I first did what BO said and defined both lower and upper limit for each span. But as I was setting it up, it was clear that the lower threshold was superfluous. If test 1 checks if it's earlier than 2am, what's the point of checking that it's later than 2 am before checking if it's earlier than 8am? We already know it's later than 2am when that check runs, because we already checked if it's earlier and it came back false. So I first tried doing it as BO said, including both a lower and upper limit, and when I found that worked, I tried removing the checks that were repeating the previous stage, and it still works. So it seems if you just set it up properly you only need one hour check for each stage Smile
I'll add a picture of how I set it up, since it's probably hard to understand from text
[Image: 25kivbt.jpg]
Now that I know the code runs properly, I'll incorporate it into the sleeping code. I was using it as guardian bhav for a painting interaction while testing, easy to test that way.

I'm exhausted, so I'll head off to bed now. I'll be back with my second question when I have an example to show what I mean, easier when there's something concrete to refer to Smile

0
#6 02-03-2016 
Yeah, sometimes it's just a matter of redoing it. Even if you think you did it right the first time. I'm glad you got it fixed now, @gummilutt Smile Celebrate

1
#7 03-03-2016 
I figured out part of my stack object stuff, but I can't seem to find how to set up a line in my code. I want to test the stack objects GUID. Does anyone happen to know how to set that up? I managed to make a modified version of the BHAV that EA uses to check if a Sim owns a car that fits my purposes. I know Stack Object is the car the Sim owns, so now I just need to figure out how to check the GUID of that and my tiny ownable cars are pretty much finished Smile I'm really excited about it.

Perhaps MSD or mustluvcatz?

EDIT: More than a year later I found myself needing to test guid again, and in trying to find a method I came upon this thread again. So when I then found a solution I thought it might be a good idea to go back and put the solution in this thread, since I clearly found it again so maybe someone else will too.

The solution is primitive 0x0020 Test Object Type. Often used by maxis where there are different objects in the same category and it needs to decide which animations to use (toilet vs urinal for example). Setup is
[prim 0x0020] Test Object Type (Stack Object ID, is instance of: GUID)
Raw data for that is 4C1E670000000A000000000000000000. Change guid to the one you want, of course Tongue
(This post was last modified: 09-12-2017 09:20 PM by gummilutt.)

0
#8 03-03-2016 
There is a code in Manage Inventory to work with GUIDs. But you don't test a specific object to see what GUID it has. You test if an object of your desired GUID is present in a certain inventory. If so, the test returns True and the index variable will point to the object in question. And if not, the test will return false. I've used stuff like that in "No Sim Loaded" and "Spawn Objects", for example.

1
#9 04-03-2016 
Sorry, I did not follow. I know that manage inventory can check for guid, since we used that for the inventory check, but this object is not is in inventory, it's a regular car placed on the lot. I need something that works for stack object, since I know stack object is the car I want to test. Are you saying I could use manage inventory for that somehow? Smile

The tiny car in inventory approach is at a stand still. The manage inventory we used in car code does not work in school code, because stack object does not refer to the person. I either have to figure out how to edit stack object to be the Sim, and then edit it back to what it was previously, or I have to figure out a different way to set up manage inventory. I posted about it in bounding box thread, but no replies so far so at the moment I can't do anything.
EDIT: I'm still hoping to figure that part out, because children can't own cars and I'd like to be able to stop the school bus for them as well Smile I have a couple of Sim parents that I think would like to drive their kids to school.

I've been poking around in the different arguments for expressions, and I noticed you can make it check for flags and all kinds of things. So I suppose if anyone knows how to check for a specific thing that I could give to my car that will be unique to my car (meaning regular maxis cars won't have it), that would work as an alternative to checking for guid Smile
(This post was last modified: 04-03-2016 12:29 AM by gummilutt.)

0
#10 04-03-2016 
Sure you can test for an object on the lot. The lot is an inventory too, and so is the neighborhood. For inventory, select Global - Current House or something of that nature. Then, the car can be found. You don't need to give any flags to the car. The car has no inventory to store it in anyway.

0


Sorry, that is a members only option