General > Developers Corner

Chat icon problem With ulx

(1/2) > >>

Nightmare2244:
NOTE: I tried to add the whole code in here, but it's WAY to big, like 26k characters, so unfortunately I had to use pastebin

LINK: http://pastebin.com/GK9xJanS

So as can see this is a nice chatbox, but... I have problems. I am trying to add my own custom ulx group for this chatbox, and whenever adding this to code



--- Code: ---local OwnerIcon = Material("C:/garrysmod/garrysmod/materials/icon16/shield_rainbow.png") // ULX Owner custom group, added to custom code below.
--- End code ---
(As seen on line 30) It doesn't work, I also made sure that I added this to the code below


--- Code: --- table.insert(TextTable, i+1, TextTable[i]:Nick())
            TextTableNum = TextTableNum + 1
            if !NoFirstPlayer and ShowIconsForPlayers then
                if ShowPlayerAvatars then
                    avatar = vgui.Create("AvatarImage")
                    avatar:SetPlayer(TextTable[i], 16)
                    avatar:SetSize(16, 16)
                    TextPosX = 17
                elseif ShowPlayerRanks then
                    if TextTable[i]:IsSuperAdmin() then
                        icon = SuperAdminIcon
                    elseif TextTable[i]:IsAdmin() then
                        icon = AdminIcon
                    elseif TextTable[i]:IsUserGroup("owner") then
                        icon = OwnerIcon
                    else
                        icon = DefaultUserIcon
                    end
                    TextPosX = 17
                end
--- End code ---
(This starts on line 374)

As can see I added elseif TextTable:IsUserGroup("owner) then

and for some reason it uses the superadmins shield preset, mostly because I made the owner rank inherit from superadmin, which gives me a hunch of why it wont add it's own shield. but how do I fix this? Thanks!

JamminR:
1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

Nightmare2244:

--- Quote from: JamminR on March 29, 2016, 07:02:04 PM ---1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

--- End quote ---

I will try, I will report if it works.

MrPresident:

--- Quote from: JamminR on March 29, 2016, 07:02:04 PM ---My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

--- End quote ---

You're correct.

If..ElseIf..Else logic works in a manner that once one condition is met, the code is executed and the if block is escaped.
If more than one condition is possible to meet, you should always put the more desirable first in your statement.

Nightmare2244:

--- Quote from: JamminR on March 29, 2016, 07:02:04 PM ---1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

--- End quote ---

You where quite right on this part, it gives me the tag, and the shield like wanted, but leaves my SuperAdmin having the shield of the admin now. And I don't know if adding if statements to every adminicon in the code would work or not?

Heres the code now:

--- Code: ---if TextTable[i]:IsUserGroup("owner") then
icon = OwnerIcon
elseif TextTable[i]:IsSuperAdmin() then
icon = AdminIcon
elseif TextTable[i]:IsAdmin() then
icon = SuperAdminIcon
--- End code ---
As can see the if statement is now the owner, as I wanted a seperate shield for that. Knowing that the creator of this chatbox didn't really think they would want any other shield higher than superadmin shows this, but what gets me is that before it worked with superadmin and admin having their own seperate shields because it calls the first if statement of course, and then the first elseif statement, the others are ignored and the code moves on. So I am just trying to get if I need to add a if statement of each individual shield, or if I just need something else.

Navigation

[0] Message Index

[#] Next page

Go to full version