Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.12
more ▼

asked Jul 27 '16 at 01:36 PM in Blueprint Scripting

avatar image

13 2 2 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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 :)

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

more ▼

answered Jul 27 '16 at 02:03 PM

avatar image

896 36 8 38

avatar image Halokllr Jul 27 '16 at 02:06 PM

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?

avatar image Marooney Jul 27 '16 at 02:10 PM

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 :)

avatar image Halokllr Jul 27 '16 at 02:14 PM

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

alt text

bphelp.png (276.0 kB)
avatar image Marooney Jul 27 '16 at 02:39 PM

Screenshots are always welcome :)

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.

avatar image Marooney Jul 27 '16 at 02:20 PM

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 :)

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 :)

avatar image Halokllr Jul 27 '16 at 02:25 PM

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.

avatar image Marooney Jul 27 '16 at 03:36 PM

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)

alt text alt text

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.

checkarray.jpg (160.4 kB)
addnewday.jpg (53.3 kB)
avatar image Marooney Jul 29 '16 at 10:36 AM

Just let me know if you need anything else or if this solution works for you :) 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)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question