Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help on getting a card selecter to work. Please?

Asked by 8 years ago

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:

001c1 = game.workspace.c1.Decal
002function onClicked()
003    local a = math.random("1", "52")
004    print(a)
005    if a==1 then
006        c1.Texture=rbxassetid://393533133
007    elseif a==2 then
008        c1.Texture=rbxassetid://171982569
009    elseif a==3 then
010        c1.Texture=rbxassetid://171982595
011    elseif a==4 then
012        c1.Texture=rbxassetid://171984344
013    elseif a==5 then
014        c1.Texture=rbxassetid://171984333
015    elseif a==6 then
View all 112 lines...

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.

0
It needs to be a string, .Texture = "rbxassetid://1234", also, try using tables and iterations next time,it's easier. 1N0body 206 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

01local c1 = game.workspace.c1.Decal
02 
03-- just make a list so we dont need have lots of elseif
04local textureList = {
View all 29 lines...
Ad

Answer this question