goto in Usecode C?
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
goto in Usecode C?
Is there a way to do a goto in Usecode C? For example I'm playing with the Copy Protection function, and it loops back to the top until the number of questions answered correctly is above 3. But there's no equivalent in Usecode C?
Re: goto in Usecode C?
You can use while or do...while for this purpose; it is better than using a goto, and you can almost always restructure the code to use one of them instead (in FoV, I think only LB's usecode needs a slight twist to rewrite without a goto).
UCC does support goto statements and labels; but here is something to keep in mind about goto.
UCC does support goto statements and labels; but here is something to keep in mind about goto.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
Thank you Marzo. Is there a good example in any of the official mods I can look at?
Re: goto in Usecode C?
None of them use it; but it is like ucxt output:
Which can be done as:
Really, there is nothing to be gained by using goto. And using it is a guaranteed reject on any pull requests, in case you are wondering.
Code: Select all
loop_start:
//code
if (stuff) {
goto loop_break;
}
// more code
goto loop_start;
loop_break:
Code: Select all
while (true) {
//code
if (stuff) {
break;
}
// more code
}
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
I'd much rather use while or do just out of avoiding bad habits. That's what I was hoping for an example on. Looks like it is used in the Keyring mod but not SIfixes.
Re: goto in Usecode C?
Here is a bit more information on while and do...while, then:
'continue' and 'break' are also supported inside 'for', 'converse'; 'break' is also supported in 'switch' statements.
Code: Select all
do {
// code
if (condition1) {
break; // Exits the loop
} else if (condition2) {
continue; // Goes back to the 'do'
}
// more code
} while (condition3);
while (condition1) {
// code
if (condition2) {
break; // Exits the loop
} else if (condition3) {
continue; // Goes back to the 'while'
}
// more code
}
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
I'm stuck on fixing Pomdirgun's code, where he has an event == DEATH but it loops back to STARTED_TALKING if you haven't talked to him yet. When I try to do this as close to the original code as possible, killing him freezes the Exult engine. I want to see flag 0xCC for his death, but it's not working. I'd like to be able to run his conversation if it doesn't occur prior to his DEATH.
Otherwise I have him fully reimplemented.
Otherwise I have him fully reimplemented.
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
I think I figured this out, I was trying to "do it right" by simplifying it but the original code works better.
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
Missing quotes on a set_npc_name string got me. Added this feature request:
https://sourceforge.net/p/exult/feature-requests/187/
https://sourceforge.net/p/exult/feature-requests/187/
Re: goto in Usecode C?
Are you sure you don't just have a variable or function with that name? UCC simply does not work like that, it would try to find a variable or function with that name (spitting out an error if there was neither) and Exult would then try to interpret what was given as a string, probably with bad results.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
You're right as usual. The name I was setting was the same as used in the function name. Would it be best practice to use funcName instead of just Name? Or npcName?
-
- Posts: 1219
- Joined: Thu May 14, 2020 1:34 pm
Re: goto in Usecode C?
As I've been hacking my mod, I've been using these conventions:
shapeName
npcName
spellName
eggName
cutsceneName (these are sometimes in shape code but usually egg code)
The do / continue / break is handy for converting the antechamber ambush code, for example. It uses a loop between x-left and x-right to place each energy field.
The game start rabbit code also uses a loop to clear some NPC flags. That's why setting some flags in ES for SI+SS won't stay through a game start.
shapeName
npcName
spellName
eggName
cutsceneName (these are sometimes in shape code but usually egg code)
The do / continue / break is handy for converting the antechamber ambush code, for example. It uses a loop between x-left and x-right to place each energy field.
The game start rabbit code also uses a loop to clear some NPC flags. That's why setting some flags in ES for SI+SS won't stay through a game start.