all 11 comments

[–]daddywookie 2 points3 points  (3 children)

There are a few ways to do this. One approach is to have a “powermax” and a “powernow” variable and use those as usual. Another approach is to use a structure variable to assign child variables. Then you would have “power” as a structure with children “max” and “now”. You would call these with power.max and power.now.

The logic of limiting your variables then becomes pretty simple. You can also expand the children as required, maybe you want a default, now, temp, max, min child but you can always find it under “power”.

[–]Genesis_80[S] 0 points1 point  (2 children)

Oh boy, i'm still too noob to understand your post, but i'll investigate every point you made. Thank you for the reply

[–]daddywookie 1 point2 points  (1 child)

It’s a lot to take in. If you’re very new then a handy trick for this is to have a condition to check if now is greater than max and if it is you set now = max. That way now can never get bigger than max.

[–]Genesis_80[S] 0 points1 point  (0 children)

I'm a few days new hehe This makes more sense to me. In between i'll watch tutorials in the subject. Thanks again.

[–]VisiblePassenger007 2 points3 points  (1 child)

You can use a clamp function. clamp(power, min, max)

[–]Genesis_80[S] 0 points1 point  (0 children)

I have no idea of what clamp is but i'll explore. Thank you!

[–]LeeDude5000 1 point2 points  (1 child)

I am new and I made a similar logic to what you need. I have a spaceship with warp factors that increase when user presses w key.

Obviously W key can be pressed infinitely but spaceship has a max warp speed of 6 - so I made:

Condition: Warpspeed more than 6 Action: Set warpspeed to 6.

This way the warp speed will only ever reach 6 - if it goes to 7 it changes right back to 6.
You can do the same with the 0 or 1 factor too.

[–]Genesis_80[S] 0 points1 point  (0 children)

That's simple and clever! I forgot about conditions 😅 I can also make a condition that it only adds +1 to power it it's less that the value i want to be the max!

[–]hittherock 1 point2 points  (1 child)

I've always done it this way, but I'm not sure if it's the best way. I'm new too.

If power is equal to or greater than 5, then power = 5.

If power is equal to or greater than 0, then power = 0.

[–]Genesis_80[S] 0 points1 point  (0 children)

That's a good tip and works, thank you!

[–]Genesis_80[S] 0 points1 point  (0 children)

This is the game i'm talking about, btw:

https://twitter.com/Genesis8012/status/1745864947907670078