|
Can you make a variable that any script (even if there are multiple scripts) can all access?
Ex.
Script1
-------
global time = 0
do while true
wait(1)
time = time + 1
end
Script2
-------
do while true
if time = 60 then
msg = Instance.new("Message")
msg.Text = "A minute has passed since you started the game."
msg.Parent = game.Workspace
wait(4)
msg.Parent = nil
end
I understand that there isn't a "global", at least - I don't think it is -- perhaps all variables default to a global value? |
|
|
If I understand what you are saying correctly, you could try adding an intvalue in. It is basically a variable any script can access. I forget how to add one in though. Try hitting;
Insert>Object>IntValue |
|
|
...it kind of works, but I'm not sure.
Isn't
print("This is a statement.")
supposed to go on to the Output window?
Here's what I've got in Test1 and Test2 scripts (where that intvalue is 'ATime')
----------------------Test1
print("Opened Test1 Timer")
do while true
wait(1)
game.Workspace.ATime.Value = game.Workspace.ATime.Value + 1
end
-----------------------Test2
lval = 0
print("Opened Test2 Printout")
do while true
do while lval = val
val = game.Worksapce.ATime.Value
end
print(val)
lval = val
end
shouldn't that work? It's 2 different scripts and that ATime intvalue.
In the output, it doesn't show anything! |
|
|
OK - I just found my spelling error in 'val = game.Worksapce" rather than Workspace, and even tried using messages/hints, but still - nothing is coming up. |
|
|
Try moving "do while true" to the line directly above the print commands. There wasn't any script defining when the print command should be initiated, so it wasn't doing anything. |
|
|
what? you mean that Lua requires you to tell WHEN you want the command to be processed?
I only want the print command to be done once, and after that I want the update print command to print when ever there was a time change, which I programmed.
I've converted them to messages as well, but I also have the print included.
|
|
|
Yes, as far as I know, you need to define when a command is processed. Usually after a function such as "onTouched" or something of the sort. If you only want it to do the print command once. Try doing something like this.
print = 1
if "print" == 1
then
print() --Put print command here
"print" = 0
--continue script
I'm not sure if this will work, as I haven't tested it, but something only those lines should do the trick. Have you had privous experience in programming? Since for someone who just learn LUA, those are some pretty complicated scripts. |
|
|
Well...
Although I've done many years of basic programming (about 4 or 5), I'm just getting into the more complicated and up-to-date ones, like VB and in this case Lua.
I tried doing this:
do while true
print("Hello World")
end
and it didn't work either... I don't get it, really.
Perhaps the "Hello World" shows up elsewhere?
As for the scripts complications... as I've said I've done programming before. It's just that I don't know everything about Lua yet... (but I will soon... :) )
I'm unsure if what you've said is true... I understand that with functions, like in OnFunction do ____, obviously it only occurs at certain times. But what about the simple statement, "print("Hello World!")" that shows up at the beginning of each script if you don't delete it? It is just 'run', isn't it?
Also, I don't think you need
If "print" == 1 then
I think it's just
If print == 1 then
--what ever
end
... AAH!!! I just realized my mistake!
I'm so used to
"Do
...
while x = 3"
That I didn't do
"while true do"
I did
"do while true"!
That should fix it up...
and no you don't need to have an if/then statement. It doesn't make a bit of difference! That's just extra programming. You need functions to simulate events. |
|
|
Thanks anyway, shanethe13! |
|
|
Oh, I also missed that small mistake with the "while true do" statement :) I haven't done much with print commands, and every script I've seen had a function of some sort near the top. I'm also just learning LUA now, I've had experience with other languages such as basic, or sadscript, but this is my first time actually trying LUA. |
|
|
I'd tell you if it works, but every time i try and go in the program crashes! I'm going to try a restart of the computer, and then if it doesn't work...
I don't like the sounds of that! I might have to completely restart! (That is, restart since the last time I saved it on the hard drive!) |
|
|
When it crashes do you get a Runtime-Error of any sort? And is it crashing when you launch Roblox Studio, or when you try to run the script? |
|
|
It won't open. I click Visit Solo, and it eventually it comes up with a White screen, but it doesn't actually load. It "Isn't responding". I'm about to try a reboot, now. |
|
|
|
OK - that might save my place after all. I'll try it and report back... |
|
|
YAY! IT WORKS!!! THANK YOU THANK YOU THANK YOU!!!
Now to just figure out how to delete the scripts that are causing the error.. |
|
|
When I pressed "Play" - it froze up... very interesting... |
|
AnaminusTop 100 PosterJoin Date: 2006-11-29 Post Count: 5945 |
Here, you can do this all in one script:
------------------------------------------------------------------------------------------
Time = Instance.new("IntValue") --Creates a new IntValue
Time.Value = 0
Time.Parent = game.Workspace
function sayTheTime()
if Time.Value >= 60 then
msg = Instance.new("Message")
msg.Text = "A minute has passed since you started the game."
msg.Parent = game.Workspace
wait(4)
msg.Parent = nil
Time.Value=0 --Resets the value to 0.
end
end
while true do
Time.Value = Time.Value+1
sayTheTime()
wait(1)
end
------------------------------------------------------------------------------------------
*This is going to display the message every minute.
?-Anaminus-? |
|
|
yes, that would work, but it doesn't with what I'm trying to do.
I want a timer that "runs in the background". Basically, how do I access that variable in other scripts? The "time" variable. The scripts aren't cooperating with me... |
|
FunctionMJoin Date: 2017-09-14 Post Count: 175 |
b1
|
|
FunctionMJoin Date: 2017-09-14 Post Count: 175 |
b2
|
|
FunctionMJoin Date: 2017-09-14 Post Count: 175 |
b3
|
|
FunctionMJoin Date: 2017-09-14 Post Count: 175 |
b4
|
|