Adding Array Element with Default Values?

I’ll try and keep it as least confusing as possible. Basically I have a struct array and inside each struct is a Date Time and an array of 14 objects. In the app, each new day another element is added to the struct array, but the only thing that changes is the Date Time. Does just using the add node do that without needing to define the values?

Hi there,

so you are asking if the DateTime variable of your struct will be automatically initialized with the current date?
Short answer: Nope. But you can try it out for yourself too :slight_smile:

There is no effort to initialize your struct at all, just set your values in MakeStruct…Node. The Array does not know what you want to do with your Date.

hope that helps, Marooney

I’m not wanting it to automatically initialize. I do a check and compare the Year, Month, and Date of the last item in the index to the current Year, Month, and Date and if any of those three numbers are higher, then add another to the structure array and set that DateTime variable to the current DateTime.

Does that make sense?

Have changed my answer, since i do not think you will need the Now-Node XD Your game will not run over multiple days in realtime I guess. Still figuring out how to tell you the answer for your comment :slight_smile:

Please ignore how ugly the BP is right now. All I’m trying to do is add another to the array, not set the date or anything let. Maybe this picture can help put in to words what I can’t haha

Yes, as I said, you need to set the DateTime of your struct for yourself. It does not initialize for it self, not for RealTime-Date (that would be the only possibility) and cairtainly not a number only you know :slight_smile:

Who decides when a new Day starts? I guess you want to use an Timer? Or is it round based? Because whenever a Timer says the day is over, or when the Round says the day is over, then you add a new struct. Because then you can be sure you will need a new struct for the next day. No need to check Array-Entries of old days for that.

If that makes sense :slight_smile:

Yepp it makes sense! Like I said, I’m not trying to actually set the DateTime, I’m just trying to add another “Dates” to the array itself and set the information later.

The new day starts literally on a new day. The check is done to see if a new struct needs to be created or if we’re using the same struck from before. We’re using this to train animals and to display the statistics, we need to be able to look at data from every day the app was used.

Example: Today is 7/27. We use the app. Tomorrow we use the app again. The app checks the last date used and compares it to today’s date (which would be 7/28). Since it is literally a new day, make a new struct.

Screenshots are always welcome :slight_smile:

Well you are adding the last Item of the list again? You basically copy the struct. You need to keep in mind, you have got an array in it. Every Struct has access to the same array since you copy (share) the Reference of that array.

You can not change values of structs anyway, so you need to create a new one. Where you set the new DateTime Value and you additionally copy the old values over (what you probably do not want to do). So you need to create a new array with your 14 objects as well.

Edited it, to avoid misunderstandings.

So you say you create a new Struct only if it is a new day. So in fact you have one Struct per Day the player plays the game.

You need to set the DateValue for the Day because you can not change it without recreating it again. You need the DateTime Variable for the Day checks, so it must be the correct value on initialization, else you will have conflicts on the next check.

If you need to set a DateTime later on for what ever reason, i would suggest an additional DateTime variable. Keep in mind that you when ever you change it, you need to create a new struct and replace the array element.

You can still use objects instead of structs so you can modify values as you want, without replacing array elements.

Here a sample how you could handle this. (Its not tested, but I have done date calculations often enough to be sure it will work that way)

100360-addnewday.jpg

EventBeginPlay is not the best place though if the Day changes during the game, but you want it to have in your GetCurrentDay function that always checks the time and returns you the last element. (Just a Sequence-Node at the beginning of the whole execution wire and “Then1” returns the last element)

Perhaps it helps you to get your head around, just tried as far as i understood. I am not sure what you want to do with the Object Array, you can fill it in AddNewDay or later on.

Just let me know if you need anything else or if this solution works for you :slight_smile: My sample contains at least what you really need, no matter what you need to handle additionally:

Struct-Initialization within AddNewDay (which answers your question)

Date-Comparison, where you just need to prepare the DateTime with Year,Month,Day accuracy. (If you would add Hours to all DateTimes then you would get one array entry per hour. If you would use Year,Month only, then you would have one entry per month. Just as example for better understanding)