ACC goto support patch

Any utility that assists in the creation of mods, assets, etc, go here. For example: Ultimate Doom Builder, Slade, WadSmoosh, Oblige, 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.
User avatar
Borg
Posts: 56
Joined: Sun Jun 22, 2008 12:00 am

ACC goto support patch

Post by Borg »

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
determin1st
Posts: 57
Joined: Wed Oct 06, 2021 11:23 am

Re: ACC goto support patch

Post by determin1st »

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

Code: Select all

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
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: ACC goto support patch

Post by Rachael »

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
Borg
Posts: 56
Joined: Sun Jun 22, 2008 12:00 am

Re: ACC goto support patch

Post by Borg »

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 all

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 all

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
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: ACC goto support patch

Post by Rachael »

Borg wrote:real programers arent afraid of gotos ;)
A real jester wears a funny hat. No true jester ever wouldn't.
User avatar
Borg
Posts: 56
Joined: Sun Jun 22, 2008 12:00 am

Re: ACC goto support patch

Post by Borg »

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
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: ACC goto support patch

Post by Rachael »

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
boris
Posts: 769
Joined: Tue Jul 15, 2003 3:37 pm

Re: ACC goto support patch

Post by boris »

Code: Select all

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;
?
User avatar
Borg
Posts: 56
Joined: Sun Jun 22, 2008 12:00 am

Re: ACC goto support patch

Post by Borg »

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
TDRR
Posts: 825
Joined: Sun Mar 11, 2018 4:15 pm
Location: Venezuela

Re: ACC goto support patch

Post by TDRR »

Posting in case you don't know- BCC exists and has gotos implemented. It also has short circuit evaluation (completely removing the need to use goto in this example, anyway). It also is just better than ACC and there's little reason to use ACC over it, as BCC is 100% compatible with ACC and none of the extra features are mandatory, other than short circuit evaluation (that and ACC 1.58 has nothing BCC didn't already have, other than a handful of new definitions in zcommon.acs).

https://github.com/positively-charged/bcc

I know this topic is a few months old, but I really don't wanna see someone wasting their efforts (unless this is just for fun or something) just because they might not know this has already been done.
...and every opportunity I have to spread awareness of BCC's great features is one I have to take :p
User avatar
Borg
Posts: 56
Joined: Sun Jun 22, 2008 12:00 am

Re: ACC goto support patch

Post by Borg »

Yeah, I saw your BCC. I might try to use it one day :)
And yeah, I didnt go implemented short-circuit evaluation in ACC, too much effort indeed.
Im happy with goto now :)

Unfortunately, I dont mod much these days. My playerbase evaporated, so my motivation is uber low.

As for changing ACC, im acustomed to hacking here and there ;) for fun as well.
I have tons of forked projects (C mostly), a bit of disassembled games where I do binary patching to fix bugs or
improve things ;)

Return to “Creation, Conversion, and Editing”