#modulescript not working with self
112 messages · Page 1 of 1 (latest)
** You are now Level 1! **
I see, how do you use self for other functions? I tried it for printsystem() it just printed (“can’t add arthemical value”)
Even though I have gas and rocks set to 20 and 10
you are setting the printSystem wrong
what’s wrong with it?
o
because u want to see the gas and rocks of an object
so the function is child of the self(object)
not the class(NewgenTable)
no
and other thing
u need to set the object to a variable
like this
Hold ima try that
var = Class:new()
and call var:PrintSystem
the : is for reference the object automatic
Ok I fixed that above
u need to put in the construtor
** You are now Level 3! **
its not that
Print system?
** You are now Level 2! **
NewGenTable = {}
NewGenTable.__index = NewGenTable
-- Construtor
function NewGenTable.new(gas, rocks, shards)
local self = setmetatable({}, NewGenTable)
self.gas = gas
self.rocks = rocks
self.shards = shards
function self:PrintSystem()
print(self.gas + self.rocks)
end
return self
end
return NewGenTable
done
and in the other script u do:
randomTable = require(LOCATION)
local obj = randomTable.new(10,10,10)
obj:PrintSystem()
any questions now?
honestly I’ve been using constructor then the function for everything
just what I saw on the dev forum
I appreciate you showing me self function
u need to see various contents like youtube, discord, dev forum, API
i can recomend u a OOP starters video if u want
Sure
I have one question for self:printsystem, why don’t we use NewGenTable:PrintSystem instead?
Ima save that
its old but for starters works well
That’s a good playlist
wait a sec
i gonna draw a quick ex
alright
its ok is the car the self?
honestly i cant explain too much because i dont know how can explain in a easy way
correct
correct
In all of my object oriented programming videos, I use self. Its a keyword that makes your code more readable and understandable, but doesn't change anything. In this video, I explain how it works. Hope you enjoy!
Object Oriented Programming Roblox: http://bit.ly/2XQfWcG
Socials:
- Discord Server: https://discord.gg/cb6jncQ8sr
- Twitter: https...
Im kinda getting it
can self be anything
Ok
you can you use self in other functions because its connected to the constructor?
example
construcot has car properties
in the constructor holds the functions and variables, self in this case represent the table holding the things
and you create a function for the car like speed:() , but you need the car properties so you have to use self to pass the data onto it
ah
ok
hm
** You are now Level 3! **
if u need help with anything ping me and i will try to respond
have a good day
5am in the country i live
Hey bro its starting to make much more sense to me
self is fairly easy to use
I think my problem was calling the functions from the scripts
self is pretty much what you set it to, its just a way to pass information onto another function without redefining mutiple times.
Yeah it is just logic