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 » Scripters
Home Search
 

Re: How can you compare variable values?

Previous Thread :: Next Thread 
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
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
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
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
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
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 is not online. 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 is not online. 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
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
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 is not online. 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 is not online. 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 is not online. 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
matt1020304050 is not online. matt1020304050
Joined: 24 May 2008
Total Posts: 4475
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 is not online. 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 is not online. 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 is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
04 Apr 2015 11:21 PM
I believe matt means variables that contain properties
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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