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"

How to transfer the last known value of a looping variable to other variable?

hello i have been making a 2d sidescroller game and stuck at a point where i need the total distance travel to show player their scores but i cant take the value to distance traveled because it is constantly looping and when player dies the value of other variable becomes zero. The variables are shown in image:- 1. total distance traveled - The one who's value is needed. 2. run - The one in which the distance value will be set. alt text

Product Version: UE 4.14
more ▼

asked Mar 28 '17 at 08:12 AM in Blueprint Scripting

avatar image

6 1 3 5

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

1 answer: sort voted first

I do not really understand what variables of yours have valid values and which don't right now, but here is what I would do: Take the PlayerSpeed variable you have, and add it to the TotalDistanceTravelled * TimeDelta in your tick function. This should set the value of TotalDistanceTravelled correctly.

more ▼

answered Mar 28 '17 at 08:32 AM

avatar image

1.2k 46 29 59

avatar image Sid909 Mar 28 '17 at 11:47 AM

Sorry I don't understand, I just want to know how to take the total distance travelled variable's value and set its value into another variable to save it.

avatar image pulp_user Mar 28 '17 at 11:57 AM

If you already have these variables, then all you need to do is to drag the variable wich you want to read from onto graph while holding CTRL. Then drag the variable which you want to write to onto the graph while holding ALT. You just need to drag the pin from the read variable - into the pin of the write variable.

You can see this on the graph that you posted: The very lower left node is a read node, and the node after "AddDistance" is a write node. Just plug the read node into the write node.

avatar image Sid909 Mar 28 '17 at 03:34 PM

Can you please post a image of a blueprint to show distance travelled by player in HUD and also to save it somewhere. Please ,It will be a great help to me.

avatar image pulp_user Mar 28 '17 at 04:57 PM

This graph will transfer the last known value of the variable "Distance Travelled" into the variable "Total Distance Travelled" each frame. I'm not sure what you want to see about the HUD.


unbenannt.png (41.8 kB)
avatar image Sid909 Mar 29 '17 at 02:09 AM

I want to add 1 in distance travel every frame and when I dead condition is true then I want the last value of distance travel into other variable. What my unreal engine doing is that it add 1 in every tick but when I die it don't give last value to other variable. I know my ques is little bit confusing but I can't find find a way to explain better than this.

avatar image Sid909 Mar 29 '17 at 02:49 AM

Hope these images will make you understand betteralt text

avatar image Sid909 Mar 29 '17 at 02:52 AM

alt text

avatar image pulp_user Mar 29 '17 at 07:49 AM

ok these screenshot indeed help. This is what you have to do:

Currently your Run variable is an array of floats. Make this to float only, no array, just like Total Distance Travelled.

In your https://answers.unrealengine.com/storage/attachments/132001-variable%20in%20which%20looping%20value%20of%20total%20distance%20travel%20storing.gif

graph, set the Run variable like this: alt text

In your https://answers.unrealengine.com/storage/attachments/132003-scripting%20of%20hud%20when%20dead.gif

graph, you don't need the "Get" node anymore. Connect the "Target Run" node to the "To Text (float)" Node directly.

unbenannt.png (114.3 kB)
avatar image Sid909 Mar 29 '17 at 09:40 AM

I followed instructions but still getting 0 when dead, not the value of distance travelled saved in run.

avatar image pulp_user Mar 29 '17 at 09:43 AM

That may be because your AddDistance event doesn't get called if you die? You need to set the Run variable when you die before you change the TotalDistanceTravelled (i guess you reset this one if you die).

You could for example make a "OnDeath" event where you set the run variable.

avatar image Sid909 Mar 29 '17 at 09:47 AM

Please can I get an image example it will be more easy for me understand from that.

avatar image pulp_user Mar 29 '17 at 09:54 AM

Sorry, but this is not something one can explain with a few images. I would suggest your read up on the documentation. You also seem to lack some very basic knowledge about blueprints, so I would strongly suggest that you practice using blueprints in general, maybe with some tutorials online. I would like to close this question, because I don't think that this discussion is going to lead to a solution.

(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