Scripting Discussion

Someone opened the box. Now you're a potato.
User avatar
dferrantino
Post Nympho
Post Nympho
Posts: 5568
Joined: 25 Jul 2013, 13:37:12
TWG 1 Posts: 0
Location: NYC (EST/GMT-5)

Scripting Discussion

Postby dferrantino » 22 Mar 2014, 08:40:15

So, I'm going through the old scripts I used for game XL, and realized I can consolidate the shit out of my code. What was formerly this:

Code: Select all

if @role = 'Seer'
begin
   delete from tblstates where seer <> @lid
end
else
begin
   if @role = 'Vig'
   begin
      delete from tblstates where Vigilante <> @lid
   end
   else
   begin
      if @role = 'Alpha'
      begin
         delete from tblstates where Wolf1 <> @lid
      end
      else
      begin
         if @role = 'Beta'
         begin
            delete from tblstates where wolf2 <> @lid
         end
         else
         begin
            if @role = 'Gamma'
            begin
               delete from tblstates where wolf3 <> @lid
            end
            else
            begin
               if @role = 'Delta'
               begin
                  delete from tblstates where wolf4 <> @lid
               end
               else
               begin
                  if @role = 'Epsilon'
                  begin
                     delete from tblstates where wolf5 <> @lid
                  end
                  else
                  begin
                     delete from tblstates where seer = @lid or Vigilante = @lid or wolf1 = @lid or wolf2 = @lid or wolf3 = @lid or wolf4 = @lid or wolf5 = @lid
                  end
               end
            end
         end
      end
   end
end


Can just be reduced to:

Code: Select all

delete from tblstates where @role = 'Seer' and seer <> @lid
delete from tblstates where @role = 'Vig' and Vigilante <> @lid
delete from tblstates where @role = 'Alpha' and Wolf1 <> @lid
delete from tblstates where @role = 'Beta' and Wolf2 <> @lid
delete from tblstates where @role = 'Gamma' and Wolf3 <> @lid
delete from tblstates where @role = 'Delta' and Wolf4 <> @lid
delete from tblstates where @role = 'Epsilon' and Wolf5 <> @lid
delete from tblstates where @role = 'Human' and (seer = @lid or Vigilante = @lid or wolf1 = @lid or wolf2 = @lid or wolf3 = @lid or wolf4 = @lid or wolf5 = @lid)


I'm also 99% sure that the following will work as well:

Code: Select all

delete from tblstates where
   (@role = 'Seer' and seer <> @lid)
or (@role = 'Vig' and Vigilante <> @lid)
or (@role = 'Alpha' and Wolf1 <> @lid)
or (@role = 'Beta' and Wolf2 <> @lid)
or (@role = 'Gamma' and Wolf3 <> @lid)
or (@role = 'Delta' and Wolf4 <> @lid)
or (@role = 'Epsilon' and Wolf5 <> @lid)
or (@role = 'Human' and (seer = @lid or Vigilante = @lid or wolf1 = @lid or wolf2 = @lid or wolf3 = @lid or wolf4 = @lid or wolf5 = @lid))

User avatar
dferrantino
Post Nympho
Post Nympho
Posts: 5568
Joined: 25 Jul 2013, 13:37:12
TWG 1 Posts: 0
Location: NYC (EST/GMT-5)

Re: Scripting Discussion

Postby dferrantino » 22 Mar 2014, 09:38:12

God so many fucking nested If statements...

User avatar
dferrantino
Post Nympho
Post Nympho
Posts: 5568
Joined: 25 Jul 2013, 13:37:12
TWG 1 Posts: 0
Location: NYC (EST/GMT-5)

Re: Scripting Discussion

Postby dferrantino » 23 Mar 2014, 21:01:24

Aaaaaaaaaaand I'm an idiot. Found the revised scripts from game XL where I basically did all of this shit already. So long cursors and super-long-winded If statements.


Return to “The Aether”

Who is online

Users browsing this forum: No registered users and 1 guest