Yeah what about the ColorMode, ParkourMode etc. all the other specifics mode ??
I’m not using .new constructor since I don’t need it and I feel like it would cause massive issue
Yeah what about the ColorMode, ParkourMode etc. all the other specifics mode ??
I’m not using .new constructor since I don’t need it and I feel like it would cause massive issue
Wasn’t suggesting a constructor since it doesn’t look like a class but for other modes you can do the same can’t you?
If you want a non-cyclic workaround that must be the way you’re doing it, you can have a child module of GameMode called something like “Methods” (which contains all the methods and few variables that the GameMode module has), and have other files require that instead. This allows for the shared metamethods table while removing it’s cyclic behavior.
This looks like an incorrect usage of class inheritance.
Also, ideally, this shouldn’t be done with OOP, but let’s walk over it anyway:
If FallMode
inherits from GameMode
, then the latter should be able to handle all modes that inherit from it. You should probably structure your classes so that
A. All game modes run using the same method under GameMode class and
B. Each mode still has their own logical callback that we can set using a constructor.
They’re referring to the fact your GameMode class does not have a __index
metamethod, thus attempting to call any members from it will fail.
I don’t think I need a constructor for this specific scenario since I don’t have specific properties like self.timerCountdown, self.alivePlayers etc. it would be hard for my scenario I’ve watched this specific thread on OOP
Well yeah, that’s just kind of how __index works, you’re setting it to itself. So that other tables which have it as the metatable can use that __index metamethod, which would allow access to that metatable without directly referencing it.
There’s also a problem I have a Main script which the script runs. At the very start of the game when the first player arrives it triggers the vote ui but after that the voteUI will run at each endGame of the GameMode parent and repeat infinitely without using like while loop equivalence
-- SERVICES
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
-- FOLDERS
local ScriptsReplicatedStorage = ReplicatedStorageService:WaitForChild("Scripts")
local ScriptsServerScripts = ServerScriptService:WaitForChild("Scripts")
-- MODULE
local VoteLogic = require(ScriptsReplicatedStorage.VoteLogic)
local GameMode = require(ScriptsServerScripts.GameMode)
VoteLogic:initVote()
local MapChoosen = VoteLogic:ChooseMode()
GameMode:StartGame(MapChoosen)
I see 0 usage of game mode inside of the fall mode module. Remove it.
Two modules cannot require each other, you could work around by doing an importer module and then requiring and getting from there pretty sure that works. If not then I am not too sure.
Game mode should handle everything to do with the game anyway.
The problem is I need them for inheritance wait hold on I actually don’t need GameMode anyway since I call the method of FallMode.
Edit : Actually no I need to reference GameMode since it will cause this issue
or I could just put it in parameter at this point
Why are you using FindFirstChild and not WaitForChild?
Edit:
saw the issue, you didn’t say it was the print. Just merge the two or use a one way import.
Because :FindFirstChild make sure that the instance actually exist before running the code with WaitForChild if the instance doesn’t exist it will display nil
And if it doesn’t exist then handle its nil
return. This is also the same for FFC not just WFC.
Actually I don’t know the difference by looking at the name WaitForChild wait for the instance to be completely load and FindFirstChild will try to find the instance but both likely give the same output in a certain way so
I tried the if condition and neither gave them a red line so my error is I forgot a if statement to check if the instance exist or not
This was so confusing to read, please proof read.
local x = game:WFC("name")
if x == nil then
print("x returned nil.")
end
“self.mapChoosen” is nil, :FindFirstChild()
is not useless. You’re not even using it though
FindFirstChild will try to find the Instance if it doesn’t find it will display nil but WaitForChild will give a warning if it doesn’t find the Instance.
But the problem is much deeper than FindFirstChild and WaitForChild
:WaitForChild()
will yield your code untill it finds it
they serve different purposes