#random generation keeps doing weird stuff

24 messages · Page 1 of 1 (latest)

gleaming hamlet
#

fairly frequently the first room will also generate another one inside of itself for zero apparent reason

#

one of them is generating upside down what the fuck

paper compass
#

No code no help

#

Prob your how you rigged the room tho

gleaming hamlet
#

hold on i mightve figured it out lol
basically what you said, i put an exit upside down so when the room generated it turned the next rooms upside down too

#

ill see if this also fixes the other issue

#

ok it probably fixed issue number 2, let me double check some stuff and then ill get back to this

gleaming hamlet
#

,wait no thats dumb hold on

#

first script, Server

local room = require(script.Room)
local randomValue = math.random(10,25)

local prevRoom = workspace.StartRoom
room.Generate(prevRoom)

for i=1, randomValue do
    prevRoom = room.Generate(prevRoom)
end

this script is inside the script Server, and is called Room. its a module

local room = {}
room.info = require(script.Roominfo)
room.lastTurnDirection = nil
room.random = Random.new()

function room.GetRandom(prevRoom)
    local totalWeight = 0
    for i, info in pairs(room.info) do
        totalWeight += info.Weight
    end
    
    local randomWeight = room.random:NextInteger(1, totalWeight)
    local currentWeight = 0
    local randomRoom = nil
    for i, info in pairs(room.info) do
        currentWeight += info.Weight
        if randomWeight <= currentWeight then
            randomRoom = workspace.Rooms[i]
            break
        end
    end
    

    
    -- [1] Next room MUST be different from prev
    -- [2] if corner then next must turn other way
    -- [3] two stairs cant generate in a row
    
    local direction = room.info[randomRoom.Name]["Direction"]
    local hasStairs = room.info[randomRoom.Name]["Stairs"]
    local prevHadStairs = room.info[prevRoom.Name]["Stairs"]
    
    if prevRoom.Name == randomRoom.Name then
        return room.GetRandom(prevRoom)
    elseif direction and direction == room.lastTurnDirection then
        return room.GetRandom(prevRoom)
    elseif hasStairs and prevHadStairs then
        return room.GetRandom(prevRoom)
    else
        if direction then
            room.lastTurnDirection = direction
        end
        
        return randomRoom
    end
    
    
end

function room.Generate(prevRoom)
    local randomRoom = room.GetRandom(prevRoom)
    local newRoom = randomRoom:Clone()
    
    newRoom.PrimaryPart = newRoom.Entrance
    newRoom:PivotTo(prevRoom.Exit.CFrame)
    newRoom.Entrance.Transparency = 1
    newRoom.Exit.Transparency = 1
    
    newRoom.Parent = workspace.GeneratedRooms
    
    return newRoom
end

return room

this is the last one, and is inside of Room. its a module called Roominfo

local roomInfo = {
    ["StartRoom"] = {
        ["Weight"] = 0

    },
    ["LeftTurn"] = {
        ["Direction"] = "Left",
        ["Weight"] = 3

    },
    ["RightTurn"] = {
        ["Direction"] = "Right",
        ["Weight"] = 3

    },
    ["ShortCrawl"] = {
        ["Weight"] = 7

    },
}

return roomInfo
#

@paper compass this is the script, sorry for the wait

paper compass
#

Gnome code frfr

gleaming hamlet
#

yessir

#

im not smart enough to do this on my own

paper compass
#

I see no issue

gleaming hamlet
#

right? thats why im confused

paper compass
#

What’s the issue then

gleaming hamlet
#

it soemtimes spawns 2 rooms at the start

paper compass
#

It’s not the modules fault

dry loom
gleaming hamlet
#

gnomecode lol

#

after that i modify it with help from here and my own trial and error

gleaming hamlet
paper compass