Тёмный

Weighted Randomness in GameMaker 

DragoniteSpam
Подписаться 10 тыс.
Просмотров 624
50% 1

Опубликовано:

 

31 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 13   
@XorDev
@XorDev Месяц назад
Neat. I actually just did this for a game a couple of weeks ago. My approach was just slightly different, though. Instead of adding up the total odds in it's own variable, I just looped through the items, adding the last items odds to its own. So if I have item weights of [1, 2, 3] it becomes [1, 3, 6]. This makes it so that the last index is the total odds and removes the need to subtract anything from "n" because that's all precomputed. Would it make a difference? Probably not, but I thought it might be interesting to share
@DragoniteSpam
@DragoniteSpam Месяц назад
I've seen that in the wild once or twice, the math turns out the same but I think pre-adjusting the weights like this makes debugging a little harder if you (for example) print out the table and see (1, 3, 6) when you initialized it to (1, 2, 3)
@XorDev
@XorDev Месяц назад
@@DragoniteSpam Well, the benefit is no subtraction inside the loop, but realistically this will make no measurable difference unless you have extremely large lists
@DragoniteSpam
@DragoniteSpam Месяц назад
Yeah, the list would have to be massive for a single operation to make a measurable difference
@xotmatrix
@xotmatrix Месяц назад
That's how you do it. Good demonstration.
@PixelatedPope
@PixelatedPope Месяц назад
Was expecting animation curves, but leaving disappointed. Regardless, great video! Always nice to have videos that answer common discord server questions.
@DragoniteSpam
@DragoniteSpam Месяц назад
it's been 4+ years and i still forget animation curves exist half the time ヽ( 。 ヮ゚)ノ
@terohannula30
@terohannula30 Месяц назад
I guess if you have large list of items, you could transform linear search to binary search 🤔 Give items prefix sum, then find location for random value. Doing this only makes sense when same weights are used multiple times, as creating prefix sum takes some time (required to be done once, so good if reused).
@DragoniteSpam
@DragoniteSpam Месяц назад
That would probably be the logical next step after this yeah, though most games don't have THAT complex of odds tables for most things
@terohannula30
@terohannula30 Месяц назад
@@DragoniteSpam Yeah, for less than 10 items linear search is more than sufficient. I would imagine binary search would be useful for runtime generated lists, not specifically crafted ones. Like you have a large quantity of instances, and you want to pick a handful of them based on some attribute as the weight.
@Planarwalk
@Planarwalk Месяц назад
Me: var n = random_range(random(50), random_range(50, 100)); :D
@Limekys
@Limekys Месяц назад
Are you really copying and pasting lines? Just press Ctrl + D
@DragoniteSpam
@DragoniteSpam Месяц назад
@@Limekys i do that all the time by accident but never remember what the shortcut is
Далее
A Guide to Making Video Game Music
10:36
Просмотров 165 тыс.
СОБАКА И  ТРИ ТАБАЛАПКИ Ч.2 #shorts
00:33
The Basics of Palette Swapping in GameMaker
34:53
Просмотров 1 тыс.
Apple, Stop Putting Things On the Bottom Please
9:16
Просмотров 490 тыс.
The Best Games from GMTK Game Jam 2024
23:45
Просмотров 499 тыс.
2D and 3D Cloud Shadows in GameMaker
19:31
Просмотров 971
I built my own 3D Game Engine with Open-Source Tools
15:00
How (and Why) Spelunky Makes its Own Levels
7:13
Просмотров 817 тыс.