Talk:Label

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Questions on the use of Label/GoTo[edit source]

Since my computer lacks in a proper graphic card, I can't test it on my own:

1) In the article, it says label is used to create a certain label ID. This sounds to me like the command has to be run before goTo can be called. Is that right? Because it would be a good way to exclude certain parts of a script without using if conditions for the sake clarity. For instance

short Var

;...
if Var == 0
 GoTo 1
endif
; code to exclude
Label 1
;...

as a workaround for

short Var

;...
if Var
 ; code to exclude
endif
;...

Does this work as expected? This would be useful especially for long exclusions.


2) Is label/goTo bound to only one blocktype or is it possible to switch between several blocks. For example

Begin MenuMode
 Label 1
 message "text"
end

Begin GameMode
 GoTo 1
end

Does the message also occur in GameMode? Can't imagine that, since it would make those blocktypes useless, but it's left open in the article.
Diarrhoe 12:09, 5 May 2011 (EDT)

  1. No, Label needs to be run before Goto in a give run-through of a script for the Goto to work. Also, this would be a generally bad idea, from the perspective of good coding practices. See Go To Statement Considered Harmful for the most famous criticism of label/goto — the only reason we have it at all, I suspect, is because While was not available originally. Note that it is viable, and the linked page will discuss how some programmers disagree, nonetheless goto is considered a major potential problem in any code it is used in. See also: humorous graphical explanation
  2. I have absolutely no idea, but for the same reasons that Goto is usually bad, that use strikes me as awful. That would make your code an absolute nightmare to read/follow.
Dragoon Wraith TALK 17:18, 6 May 2011 (EDT)