|
| 04 Apr 2015 10:29 PM |
How can I make the below work? Both variables are numbers, and different numbers. Yet the script will never get past the repeat but the numbers are different.
chooseSong = 1 lastPlayed = 2
repeat wait() until chooseSong ~= lastPlayed print("go") |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2015 10:30 PM |
I may be wrong
chooseSong = 1 lastPlayed = 2
repeat wait() until chooseSong ~= lastPlayed print("go")
Choose song is 1. Last played is 2.
repeat wait() until 1 isnt 2 print("go")
It's going to keep on printing go because the loop results in true. Because 1 isnt 2.
I guess you want to update chooseSong and make it 2?
"I haven't been on for a while" - Bosswalrus |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 10:30 PM |
local chooseSong, lastPlayed = 1, 2
repeat wait() until chooseSong ~= lastPlayed print'go' |
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 04 Apr 2015 10:31 PM |
| as far as i can tell this script should work fine |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 04 Apr 2015 10:32 PM |
@OP
The script you gave prints go, something else must be altering the variables for you.
I script -~ chimmihc |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 10:32 PM |
| Froast is correct, it works fine, I ran it through the command bar |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2015 10:36 PM |
Oh lol I derped.
I just posted that as an example but in my code I put something like this
chooseSong = math.random(1,10) lastPlayed = chooseSong
repeat wait() until chooseSong ~= lastPlayed
And that would never execute past the repeat since it's the same thing. I thought since it wasn't running that variables couldn't be compared. Thanks guys. |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2015 10:39 PM |
Is there a way to get the contents of a variable.
My script is basically setting those variables to the number selected from the math.random. Which in my mind was repeat wait until the variables content number is not the same as the last played variable numbers. But instead the script is comparing the actual variable.
Like lets say
x = 1
last = x secondLast = x
repeat wait() until last ~= secondLast
They are both the x variable, but what if I wanted them to be numbers. Is there a way to do that?
|
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 10:44 PM |
| @matt, that should work, just swap em 2 b local variables <3 |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 10:45 PM |
here's proof it works, run this in your command bar
local A = 'oye, mr krebs' local B = A print(B)
>local B = A >prints(B)
>the output is A
Works like a charm |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2015 11:00 PM |
No I want it to print the number not the variable.
ex:
x = 1
b = x
print(b) > x
I want it to say
> 1
Is there a way to access the contents of a variable? |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 11:02 PM |
Uhrm, if its a variable that was defined as being only one value, you can't exactly get the contents of it any other way
tables however can do dis
T = {1, 2, 3} print(T[1]) |
|
|
| Report Abuse |
|
|
vat21s
|
  |
| Joined: 07 Jun 2010 |
| Total Posts: 2508 |
|
|
| 04 Apr 2015 11:05 PM |
chooseSong = math.random(1,10) lastPlayed = chooseSong
repeat wait() chooseSong = math.random(1,10)-- You will never modify choose song again if it's not in the loop until chooseSong ~= lastPlayed |
|
|
| Report Abuse |
|
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 04 Apr 2015 11:07 PM |
"chooseSong = math.random(1,10) lastPlayed = chooseSong
repeat wait() until chooseSong ~= lastPlayed"
it looks to me like you want lastPlayed = math.random(1,10) repeat wait() until math.random(1,10) ~= lastPlayed
if this is what you're getting at: no, there's no way for you to use 'chooseSong' as 'math.random(1,10)' and have it call that each time. you could make chooseSong a function, but for this specific case it's not worth it because it would be something like function chooseSong() return math.random(1,10) end which is i.e. the same as just calling math.random |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2015 11:13 PM |
Guys forget the repeat wait stuff lol I already coded it another way and it's working.
My question now is can you identify the contents of a variable. And not using a table. |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 11:19 PM |
There are no concent(S) of a variable, just a single content unless it is not your average string, number, and bool value
>being brickcolours have the r, g, b properties (red green blue)
>vector3 properties have the x, y, z properties |
|
|
| Report Abuse |
|
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 04 Apr 2015 11:19 PM |
I'm not sure what you mean a = 1 b = a print(b) will give you 1 a = 1 b = a a = 2 print(b) also gives you one print(a) at any time would give you the value of a? |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 04 Apr 2015 11:21 PM |
| I believe matt means variables that contain properties |
|
|
| Report Abuse |
|
|