I am trying to create a game where it displays a random poker card, but I cannot get it to work. Here is the code I am using:
001 | c 1 = game.workspace.c 1. Decal |
002 | function onClicked() |
003 | local a = math.random( "1" , "52" ) |
004 | print (a) |
005 | if a = = 1 then |
006 | c 1. Texture = rbxassetid:// 393533133 |
007 | elseif a = = 2 then |
008 | c 1. Texture = rbxassetid:// 171982569 |
009 | elseif a = = 3 then |
010 | c 1. Texture = rbxassetid:// 171982595 |
011 | elseif a = = 4 then |
012 | c 1. Texture = rbxassetid:// 171984344 |
013 | elseif a = = 5 then |
014 | c 1. Texture = rbxassetid:// 171984333 |
015 | elseif a = = 6 then |
I get the error (6,25) Expected identifier, got '/' in Script Analysis, as well as error Workspace.Reset.Script:6: '<name>' expected near '/' in output.
Building upon 1N0body comment there are two general rules of programming which needs to be looked at.
"Duplicate code" - a big giveaway that your design/method of codeing needs to be changed, we write code once and only once. Then we can re-use it, this makes our code much more maintainable in the long run. There may be exceptions to this.
"Maintainability" - with this current design of code it would take a long time to add to e.g. in the middle of your if statements as well as you have fixed variables for something which may change.
optimize code
01 | local c 1 = game.workspace.c 1. Decal |
02 |
03 | -- just make a list so we dont need have lots of elseif |
04 | local textureList = { |
05 | 'rbxassetid://393533133' , 'rbxassetid://171982569' , 'rbxassetid://171982595' , 'rbxassetid://171984344' , |
06 | 'rbxassetid://171984333' , 'rbxassetid://171984320' , 'rbxassetid://171984303' , 'rbxassetid://171982720' , |
07 | 'rbxassetid://171982735' , 'rbxassetid://171982748' , 'rbxassetid://171982776' , 'rbxassetid://171982807' , |
08 | 'rbxassetid://171982794' , 'rbxassetid://171982338' , 'rbxassetid://171982229' , 'rbxassetid://171982240' , |
09 | 'rbxassetid://171982250' , 'rbxassetid://171982260' , 'rbxassetid://171982268' , 'rbxassetid://171982281' , |
10 | 'rbxassetid://171982292' , 'rbxassetid://171982315' , 'rbxassetid://171982324' , 'rbxassetid://171982376' , |
11 | 'rbxassetid://171982420' , 'rbxassetid://171982407' , 'rbxassetid://171983024' , 'rbxassetid://171982928' , |
12 | 'rbxassetid://171982942' , 'rbxassetid://171982949' , 'rbxassetid://171982956' , 'rbxassetid://171982965' , |
13 | 'rbxassetid://171982976' , 'rbxassetid://171982986' , 'rbxassetid://171983007' , 'rbxassetid://171983010' , |
14 | 'rbxassetid://171983031' , 'rbxassetid://171983046' , 'rbxassetid://171983040' , 'rbxassetid://171982129' , |
15 | 'rbxassetid://171981991' , 'rbxassetid://171982041' , 'rbxassetid://171982049' , 'rbxassetid://171982055' , |