Log In  

BBS > Superblog
Posts: All | Following    GIFs: All | Postcarts    Off-site: Accounts

I'm struggling with a function that randomly picks up an element from a table with ponderated probability. For now this is my current code:

items = {
 {value="a",probability=.35},
 {value="b",probability=.35},
 {value="c",probability=.145},
 {value="d",probability=.145},
 {value="e",probability=.008},
 {value="f",probability=.002}
} -- total probability = 1

function rnd_item()
 local rnd_number = rnd() -- between [0,0.99999)
 local i = 1
 local sum = items[i].probability
 while sum < rnd_number do
  i += 1
  sum += items[i].probability
 end
 return items[i]
end

What is the problem with the implementation? Right, In some cases it crashes because 'i' goes out of bounds. It seems that the problem occurs when rnd_number is near 1 (i.e. 0.99997) but I can't figure out how I fix it.

Is there a better implementation to solve the problem?

1
12 comments


Hi mates,

I'm having some issues with an unexpected (for me) behaviour of rnd() and tostr() functions.

Why this fragment of code prints value 1 if it's supposed that calling rnd() with no arguments produces values from 0 to 0.99999? Does tostr() perform some kind of ceil()?

local rnd_number = rnd()
printh("rnd_number:"..tostr(rnd_number),"maplog.txt")

Output:

rnd_number:0.3293
rnd_number:0.7758
rnd_number:0.5745
rnd_number:0.3691
rnd_number:1
rnd_number:0.0995
rnd_number:0.1682

I need to avoid that '1' value.

5 comments


Cart #thevoid_saturn91_v1_1-0 | 2020-11-24 | Code ▽ | Embed ▽ | No License
4

4
0 comments


Mon premier jeux

Cart #ruhohigiti-0 | 2020-11-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

0 comments


Hi there everybody,
I'd like to create a game and I found this lovely and powerful platoform.

  1. Once the game is finished could I run it on my website or it will be published just here?
  2. Is there any way to develop a game in portrait format? (1080x1920 pixels)

Anyone who can help I'd appreciate it! <3

Thanks and have a lovely day,
caliop.

1 comment


Cart #islandleste999-0 | 2020-11-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
6

6
18 comments


Cart #skullshooter-0 | 2020-11-24 | Code ▽ | Embed ▽ | No License
11

Hello!! After several months of work on and off, I am proud to share my first pico-8 game!

This is Skull Shooter, a demake/remake of the very first game I ever programmed in high school. It's a top down shmup with randomized enemies and two powerups.

Arrow keys to move, Z to shoot. Green enemies are worth bonus points, and every 50 points a boss enemy spawns that has more HP than regular enemies.

I used the song "Dimensional Rift" from Pico-8 Tunes Vol. 2 (https://www.lexaloffle.com/bbs/?tid=33675) for the ingame music.

11
2 comments


Cart #zopotosebi-5 | 2020-11-23 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Controls:

  • Arrows: Move Chad's tractor
  • Z: Shoot some grain (consumes 0.1 FARM per shot!)
  • X: Speed boost (consumes fuel!)

Goals:

  • Collect some FARM using Chad's trusty tractor and make some gainz!
  • Keep your tractor above a wheat field to collect some FARM
  • Replenish your (bio) fuel by collecting beets
  • Collect green candles (and avoid red ones!) to increase the FARM price

Enemies:

  • Fences will hurt you: avoid them! (you can pass through them though)
  • Crows will steal grain from the fields: be sure to shoot them before that happens!
  • Fox will try to hit you and steal 15% of your FARM stock: avoid them or shoot them!
2 comments


Cart #holeinone-1 | 2020-11-28 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
16

v1 (11/28/2020)

Updated with 3 new levels, 2 new object types (lock and key), sfx and music! Though I'm not sure if the sfx and music sound good together... I feel like it gets muddied sometimes and there is too much going on in the audio. Feedback is appreciated!

v0 (11/23/2020)

A golf-based puzzle game I am working on! So far there are only 3 levels but I am planning to add many more, including more types of objects. There is currently no music or sfx but I am planning to add those too, eventually.

16
6 comments


Cart #snowcaps-0 | 2020-11-23 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

5
1 comment


Cart #mudusizide-0 | 2020-11-22 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

A character and some tiles. Combined basic character and basic tilemap into one.

  • Collisions. The character can only walk on tiles with flag 0. Shout out to doc_robs he taught me mget , fget , and the whole grid system.
  • Before I was drawing the edges myself but not anymore :D
0 comments


Cart #ladderman-1 | 2020-11-22 | Code ▽ | Embed ▽ | No License
9

A little game where you need to build a ladder which is large enough to reach the other side.

9
3 comments


"Testing out Pico-8"

0 comments


Cart #thevoid_saturn91-0 | 2020-11-22 | Code ▽ | Embed ▽ | No License
3

3
3 comments


Cart #celeste_te-0 | 2020-11-22 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

A Celeste Template v2

Pls report any bugs cause I was kinda lazy so I didn't look through it while playing so some of it might be buggy

I'm sorry but I cannot post any previous versions for

secret
reasons

5
8 comments


Cart #chrprinter-4 | 2023-07-31 | Code ▽ | Embed ▽ | No License
12

v1.1 -- Added ability to clear output string by pressing Z
v1.2 -- Removed characters 0-15 as Pico-8 0.2.2 made these unusable, tweaked appearance
v1.3 -- Added characters 0-15 as code comments so they can be copied and pasted manually

This is a little tool for easily selecting and outputting characters from Pico 8's extended character set. You can build strings of any length and paste them as text using Ctrl+V or a right mouse click (on the BBS, you have to press Ctrl+C as well). I had some fun making it look like a version of the Pico-8 code editor with text characters as the icons, and since it's a pretty small program, I squeezed it down to fit in a tweet =).

Controls:

[ Continue Reading.. ]

12
6 comments


So, I'm modding a game called Andy the Adventurer and making it into more of a spider man style thing. I want the player to be able to grab onto ledges. I've already made the code for making the player go up by four pixels, but what I need to do is get the coordinates of the nearest instance of a certain sprite. Closest to the player that is. It's the most efficient way to do it I think. I have a sprite specifically for ledge grabbing, and it's invisible. In the map editor, I place it directly next to any steep ledges. So yeah.

TLDR: How do I check the top-left corner location of the nearest instance of a sprite, to the player?
Still long, but better.

EDIT: I suppose a better question would be, how do I check if an x,y coordinate is inside a certain sprite on the map?

2
1 comment


Make some burgers! om nom nom

Cart #burger_creator-0 | 2020-11-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

How to play:
arrow keys to move cursor
X to add selected ingredient to the burger
O to finish

8
1 comment


Cart #hiyokorun-0 | 2020-11-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

1
2 comments


Cart #flappycrow-2 | 2020-11-21 | Code ▽ | Embed ▽ | No License
2

2
1 comment




Top    Load More Posts ->