generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Hmm, script for each game? (mini-game question)

Previous Thread :: Next Thread 
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 12:04 AM
So, I thought it'd be fun to start a mini-games project of the sorts, however that idea may develop.

Now I have a question, should I have a separate script for each mini-game, meaning clean looking code and easily keep things organized. Or should I stuff everything into one script, could be more efficient and I could re-use some code, though I could make a little global library.

What do.
Report Abuse
Voidion is not online. Voidion
Joined: 01 Aug 2011
Total Posts: 2668
01 Jul 2013 12:13 AM
I'd recommend stuffing it all in one script. I was told having too many scripts will eventually cause lag.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 12:19 AM
I'm trying to think of a better way to sort individual game code than this...
might have to do though, was hoping to think of a more clever way :p

function runGame(game)--string
if game == "blah" then
setMap(game)
--game code
elseif game == "har" then
setMap(game)
--mo' game code
end
end
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 12:47 AM
Place each individual game's code within a table in the script. That way it's easier to randomly choose each game mode and fetch it's scripts.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 01:01 AM
I don't think there's a nice way to store that code in a table without flattening it into one line, be nice if I could do something like this:

local games = {
        {"Game1",
        local Code = print("Running game 1")
        for i = 1,10 do
                print("random code "..i)
        end
        }
}
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 01:17 AM
You can't necessarily store blank code, but you CAN store functions in tables.
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 01:19 AM
local GameModes = {
(function()
--Stuff
end),
(function()
--Stuff
end)
}

Sure it doesn't have string titles, however you don't necessarily need them. That can just be set up in the code of the function when the game loads.
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 01:20 AM
If not, then you could just write each function out as a variable, then store each one inside a table.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 01:20 AM
That's true, actually I might go down that route. It cuts out the if-statements and gives me some more options. c:
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 01:26 AM
You'd just need a simple way to check when the functions are done running. That can be done by having a variable at the beginning of the script though. Example:

local midgame = false

local gamemodes = {
(function()
--Gamemode properties and whatnot
--at end of function put:
midgame = false),
(function()
--Gamemode properties yet again.
--You know the drill...
midgame = false)
}

while true do
print('Starting new game...')
midgame = true
Spawn(gamemodes[math.random(1, #gamemodes)])
repeat Wait(0.03) until midgame == false
print('Game over')
end
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 01:27 AM
Might work. I'm actually not entirely sure how to call functions from a table. If anything it would be easier to independently define each variable, so as to cut down on confusion.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 02:08 AM
Took me a minute to figure out how, but I came up with this. c:

function bloo(bla)
print(bla)
end
local table = {bloo}
table[1]("blop")
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 02:16 AM
I prefer doing this when storing functions as variables:

local bloo = function(bla)
print(bla)
end
local table = {bloo}
table[1]("blop")

I guess whatever works for you though. You're welcome for the suggestion!
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 02:16 AM
yay, roughly what I might be doing then.

function Game1(var)--parameter if i can think of a use
print("starting game 1 "..var)
end

function Game2(var)
print("starting game 2 "..var)
end

local Games = {Game1,Game2}
local selected = Games[math.random(1,#Games)]
selected("umg i dunno...")
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 02:17 AM
oh yes, and thanks. c:
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 11:58 AM
on second thought, I might do something more like you originally said. :p

table = {{
        (function(var) -- test test
                print(var)
        end),
        Name = "Game 1",
        Instructions = "Try not to be too cool for school, bro.",
        Time = 5
        }}
table[1][1](table[1].Name.." | "..table[1].Instructions)
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 12:19 PM
A table within a table? Never thought of it for something like that. Clever.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
01 Jul 2013 12:29 PM
oh yes, 2d tables can be quite handy. c:
Report Abuse
Frezzit is not online. Frezzit
Joined: 28 Jun 2013
Total Posts: 91
01 Jul 2013 12:33 PM
That really opens my mind up. Glad we could help each other.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image