ACC goto support patch

Any utility that assists in the creation of mods, assets, etc, go here. For example: Ultimate Doom Builder 2, Slade, WadSmoosh, etc.
Forum rules
The Projects forums are ONLY for YOUR PROJECTS! If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.

ACC goto support patch

Postby Borg » Sat Dec 25, 2021 12:44 pm

Hello.

Here comes a hacky patch for ACC/ACS that adds goto statement and labels.
Its fully functional. I tested it and even already use in one of my mods, converted
nested if for more flat and simpler if + goto.

Patch is here: http://borg.uu3.net/patch/acc+goto.patch

Regards,
Borg
User avatar
Borg
 
Joined: 22 Jun 2008

Re: ACC goto support patch

Postby determin1st » Sat Dec 25, 2021 1:24 pm

times ago one man showed me how to avoid goto's :] 's like

Code: Select allExpand view
while (something)
{
  // ...
  if (thing) {break;}
  // ...
  if (anotherThing) {break;}
  // ...
  break;
}


got some lengthy script, throwed it with shovel hah, about 800 lines, but even this tech not applied in there.. i would like to have some long integers or floats.. converting floats to fixed point, ye, quite funny, but no problem :]
User avatar
determin1st
 
Joined: 06 Oct 2021

Re: ACC goto support patch

Postby Rachael » Sat Dec 25, 2021 1:56 pm

This would be useful if you decompile an ACS script. Otherwise, yes, you should avoid goto at all costs. A patch like this simply makes it possible to recompile decompiled ACS scripts with less problem.
User avatar
Rachael
^ walking stack of unfinished projects ^
Admin
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: ACC goto support patch

Postby Borg » Sat Dec 25, 2021 4:46 pm

determin1st: Oh I know how to avoid them, I just dont like to avoid them ;)
There is nothing wrong with gotos if they are used right.

Rachael: Avoid gotos? nah.. they are usefull... real programers arent afraid of gotos ;)
Anyway.. look at this:

Code: Select allExpand view
if(SetActivatorToTarget(0))
  {
  if(ClassifyActor(0)&ACTOR_PLAYER)
    {
    if(CheckInventory("Credits")<30000)
      GiveInventory("Credits",am);
    else
      am=am*2;
    }
  else
    am=am*2;
  }
else
  am=am*2;
if(SpawnForced("CrCoin",x,y,z,CTID+id)<1)
  terminate;

Vs this one, with looks much cleaner imo:
Code: Select allExpand view
if(!SetActivatorToTarget(0))
  goto mul2;
if(!ClassifyActor(0)&ACTOR_PLAYER)
  goto mul2;
if(CheckInventory("Credits")<30000)
  {
  GiveInventory("Credits",am);
  goto spawn;
  }
mul2:
am=am*2;
spawn:
if(SpawnForced("CrCoin",x,y,z,CTID+id)<1)
  terminate;


I think next item I will turn my eye on is to make conditional evaluation shotcuted.
This of course will be much harder to do :)
User avatar
Borg
 
Joined: 22 Jun 2008

Re: ACC goto support patch

Postby Rachael » Sat Dec 25, 2021 4:59 pm

Borg wrote:real programers arent afraid of gotos ;)



A real jester wears a funny hat. No true jester ever wouldn't.
User avatar
Rachael
^ walking stack of unfinished projects ^
Admin
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: ACC goto support patch

Postby Borg » Sat Dec 25, 2021 5:30 pm

Hah.. you definitly took all that too serious... Is emotikons broken here? or not render on your browser? ;)
Anyway.. This should cheer you up a bit:
http://www.textfiles.com/100/real.pgmrs

Also, I updated patch.. There was a BUG :)
Had to use a goto actually.. hah :)
User avatar
Borg
 
Joined: 22 Jun 2008

Re: ACC goto support patch

Postby Rachael » Sat Dec 25, 2021 6:01 pm

Alright. Here we go.

The reason why goto's are bad is simply because - without very strong visual cues of jump points and conditional branching, it leads to one being less able to detect bugs with these structures. Goto is great for simple code where you don't have to remember a lot and you can pretty much keep the whole thing in your head. Otherwise, things can get messy real fast. That isn't to say there never is a use for goto - even in larger projects - there is - it's just that if you can avoid it, it's often better to.

The reason why if statements and while loops are preferred is because when you use these, then you typically know where the conditionally called code stops - provided, of course, that you do yourself a favor and use proper indentation and structure for the proceeding code blocks that follow.

Everyone at some point has found some use for a goto statement. It's just that most professional programmers acknowledge that when they are present, it's so much easier to mistake code being run under undesired conditions than if they use structured blocks.

Here's a really good write-up that raises some good points about goto:
https://www.l3harrisgeospatial.com/Lear ... be-avoided

And here's another one that generally glosses over some other good points:
https://ecomputernotes.com/what-is-c/co ... -goto-in-c
User avatar
Rachael
^ walking stack of unfinished projects ^
Admin
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: ACC goto support patch

Postby boris » Sat Dec 25, 2021 6:22 pm

Code: Select allExpand view
if(SetActivatorToTarget(0) && ClassifyActor(0)&ACTOR_PLAYER && CheckInventory("Credits")<30000)
      GiveInventory("Credits",am);
else
      am=am*2;

if(SpawnForced("CrCoin",x,y,z,CTID+id)<1)
  terminate;


?
boris
I post less than Manc and Hobo
 
Joined: 15 Jul 2003

Re: ACC goto support patch

Postby Borg » Sat Dec 25, 2021 6:37 pm

In ACC logical expresions are NOT short circut.
It means.. if SetActivatorToTarget() fails, it will continue to evaluate others for wrong actor.
Here its NOT that big problem, but still, its good to know about it.
User avatar
Borg
 
Joined: 22 Jun 2008


Return to Creation, Conversion, and Editing

Who is online

Users browsing this forum: No registered users and 1 guest