#Random with limits

1 messages ยท Page 1 of 1 (latest)

worldly hazel
#

Feel free to post the code here

#

Random with limits

#

@mellow hinge Post in here instead

#

easier to keep track

#

show me the code ?

mellow hinge
#

Okay, I didn't notice that you made a thread ^^

worldly hazel
#

^^

mellow hinge
#

So this the actual code

worldly hazel
#

so you can see

#

in the start there you set propertySize to 0

#

you just want to "Get PropertySize"

mellow hinge
#

Without plugging in the get node to the set node

worldly hazel
#

You want to drag from the Get node directly

#

not via the set node

mellow hinge
#

Ah, so I don't need to add the set node to the code?

worldly hazel
#

correct

mellow hinge
#

Okay, I try

worldly hazel
#

Get is for getting

#

Set is for setting

#

changing, in other words

#

this is somewhat what i suggested

#

MAX means that it will return whichever of those 2 inputs are higher

#

so it effectively clamps the lowest value to 5.0 in this case

mellow hinge
#

The following I wanted to write before you posted your last reply.
So I deleted the set node and connected the get node to all corresponding nodes, but now I have 2 issues:
a) The default value is set to 1 and still isn't adopted
b) The size of the spline doesn't change anymore when I enter a value

#

and another issue I have and which I don't understand is that PropertySizeSideA only outputs 0 now.

#

which is probably the reason why the spline size doesn't change anymore

#

nvm, it works again. Now I will try to adopt your tip with the clamp node

worldly hazel
#

but!

#

while the clamp idea sorta works, it doenst cover it if you need some value that is squared of propertysize ^^

mellow hinge
#

If I would consider using the clamp, than only for the bottom code where the spline should be treated as rectangular shape, but I still can't figure out why and where I should use the clamp node there.

worldly hazel
#

is PropertySize something like square meters ?

mellow hinge
#

Yes, it's treated like that, but unfortunately, there is no option to choose mยฒ under units in the variable settings

#

Okay, now I probably understood why you're talking about adding a clamp node and where to implement it ^^

mellow hinge
#

The clamp node is similar to how the branch node works but in this case only for digits or not (e.g I only get an output value if the input value is between the set min and max value)?

worldly hazel
#

Clamp node clamps the value to be within min/max

#

If you input 100 with a clamp of 1 to 10. You get 10

If you input -10 to the aame clamp, you get 0

#

And value between 0 and 10 remains unchanged

mellow hinge
#

Okay, so this means that I don't need to use the second branch node in my code anymore?

worldly hazel
#

Correct

mellow hinge
#

Okay nice, thanks for your help!

mellow hinge
#

@worldly hazel
Could you please check if I used the clamp nodes correctly?
Because even if the results are more accurate now, I sometimes still get values for SideA and SideB which don't match with the set value for the entire area.
Does this probably happen because I don't do logic for retrying as you mentioned earlier?

mellow hinge
#

Another thing: I tried to use breakpoints, but I don't get any results. I assume this only works while the game is running (playing the level), but my code isn't set to work on play. Currently my code is only considered to work with PCG stuff.

worldly hazel
mellow hinge
#

@worldly hazel
Do you mean I should connect the random value to the pin for Min and disconnect it from the pin for Value?

#

Or do you mean I should add the clamp node before the random integer node and connect the return value of the clamp to the min pin of the random integer?

worldly hazel
#

The random in range works as a clamp already

mellow hinge
#

okay, so there's no need for the first clamp node?

worldly hazel
#

Correct

mellow hinge
#

I still get wrong calculations at the end. I don't know why, but it feels like the amount of wrong calculations has increased ๐Ÿ˜… ๐Ÿ™ˆ

worldly hazel
#

Second size isnt in range of full size tho

#

Second size b is directly related to size a

mellow hinge
worldly hazel
#

Size b

#

When size A gets set, so does size B

#

SizeB = TotalSize / SizeA

mellow hinge
#

True, that's the issue! I have miscalculated ๐Ÿ™ˆ

mellow hinge
worldly hazel
#

sure

#

but you're also clamping the result

#

making property size not match up ๐Ÿ˜„

#

if propertysize = SideA * SideB, you can't really clamp the second value

#

you need to clamp the first to imply clamp on the second ..

#

so since both side A and B should be minimum 2.0, it means the absolute max for the other part is less than what the max is currently

#

PropertySize = 10
Side A = Clamp (2.0, Rand()*PropertySize, PropertySize-(Sqrt(Propertysize))

mellow hinge
#

i feel how my brain is completely melting right now ๐Ÿ˜…

worldly hazel
#

It might not be completly right but

#

You gotta ensure sideA max value allows sideB to atleast be 2

#

Which actually means

#

PropertySize/2

#

๐Ÿ˜‚ im so dumb

#

SideA = randomInRange(2.0, PropertySize/2)

#

SideB = PropertySize/SideA

mellow hinge
#

So I tried your way, but I still get wrong calculations as multiplying the values of SideA and B don't match the value of PropertySize. Is this something I have to deal with?

#

A friend of mine also tried to help me in this regard and suggested including the aspect ratio to the code. We then got something like this, and there at least the aspect ratio of the area was acceptable, but we still had the issue that the sum of SideA multiplied by SideB didn't match with PropertySize ๐Ÿ˜…

#

This is so frustrating ๐Ÿ™ˆ

worldly hazel
#

PropertySize = 12
SideA = randomInRange(2.0, PropertySize/2) = randomInRange(2.0, 6.0)
SideB = PropertySize/SideA
Side A = 6.0;
Side B = PropertySize / SideA = 12 / 6 = 2;

Side A = 4.5;
Side B = 12 / 4.5 = 2.66;

mellow hinge
#

This is how you told me the code should like or?

#

SideA = randomInRange(2.0, PropertySize/2)
SideB = PropertySize/SideA

worldly hazel
#

2.0 being your lower limit,

#

if you want some lower and upper bound based on relative size,

mellow hinge
#

Okay yes, I changed the min value for the random value to get better aspect ratios

worldly hazel
#

you can do lower bound = PropertySize /4, and upper be PropertySize /2

#

minimum aspect ratio with this ^ is 1 to 4

#

1 wide, 4 long

mellow hinge
#

Okay

worldly hazel
#

maximum is equal

mellow hinge
#

I try

#

Is this correct?

worldly hazel
#

almost

#

you're using modulo and not division for SiideB

mellow hinge
#

True ๐Ÿ˜…
I tried to test something and forgot to change back

#

Sorry

#

That are the first three results I got

worldly hazel
#

seems correct?

mellow hinge
#

Does it? ^^

#

If I multiply both sides I don't get exactly 120

#

is this perhaps due to the inaccuracy of UE?

worldly hazel
mellow hinge
#

But the sum on your calculator has more decimal digits than the value calculated in UE

worldly hazel
#

They're the same

#

With max precision possible

#

If you want 32 bit precision you use "double" type

mellow hinge
#

You mean max precision possible based on what UE is capable of?

worldly hazel
#

What that variable type is capable od

#

Ue might remove a few decimals for visual presentation

#

But if you print the value, it should have all the decimals a single float can produce

mellow hinge
#

isn't exposing a variable the same as I would print it out?

#

wait ^^

#

Okay no, I thought maybe there's an option to change the precision in the details panel, but there's nothing

worldly hazel
#

Unsure why its not listed

#

When you do a math operation

#

You can right click a pin to change its type

#

Float(double) isnlisted

mellow hinge
#

Seem like the floats are already of type double-precision

#

I'm using 5.5 btw, maybe they changed anything there in this regard

worldly hazel
#

They started in 5. Something

#

But yeah so your value is at max precision

mellow hinge
#

And there's no way to tell the code to only use values which have maximum of two decimal digits?

worldly hazel
#

Not really

#

Not with accuracy afaik

mellow hinge
#

Wouldn't it possible by using a loop to exclude/include only certain values?!

worldly hazel
#

Or just more math

#

Possibly

#

I initially thought youd just want whole numbers

#

E.g. 3x5 = 15

#

24 = 2x12, 3x8, 4x6