Code that writes code?
Sebastian2203
02 Sept 2016, 16:23Hello,
Before I say anything, I am doing this on gamebook mode.
I have been fiddling with the procedural generation and I have so far managed to create a page which can turn into 9 different planets.
It has a HUGE amount of variables, and I plan to expand this by copying the code for each new page.
But the thing is, I have to modify the code for each page so it goes like this.
A17_RNGSystem1P..
And if I want to put the same code into different page I need to just rename EVERY code entry.
A18_RNGSystem1P...
And believe me, I would have to waste half a hour for one and that´s not counting the time spent on checking for any errors or typos.
So I ask you, dear forum dwellers, is there any solution or very advanced trick to avoid manual work?
Sebastian2203
02 Sept 2016, 19:00Nevermind, I already figured out the way to do it.
So this is the way to modify large chunks of somewhat "regular" code.
1: Open .txt file
2: Click "Edit" in the left upper corner
3: Click "Replace/Swap" (Not sure how you call it in English) and type the part of code.
*This might not work sometimes because it depends on the "structure" of the code.
4: Type what you want to replace it with.
Here I will show you a glimpse of my code to reveal how it worked in my situation.
if (RandomChance(30)) {
SetFlagOn ("A17_Orbit1_Unstable")
}
else if (RandomChance(25)) {
SetFlagOn ("A17_Orbit1_PlanetRing")
}
else if (RandomChance(10)) {
SetFlagOn ("A17_Orbit1_TidalLock")
//Now I needed to change the A17 into A18 and .txt helped me to accomplish that instantly instead of manually.
//I hope this might help someone, in case it does not, then sorry for cluttering this forum.
The Pixie
02 Sept 2016, 19:27You are somewhat limited in game books, and my experience is of text adventures, so I may be wrong, but you can do stuff like:
for (i, 11, 20) {
if (RandomChance(30)) {
SetFlagOn ("A" + i + "_Orbit1_Unstable")
}
else if (RandomChance(25)) {
SetFlagOn ("A" + i + "_Orbit1_PlanetRing")
}
else if (RandomChance(10)) {
SetFlagOn ("A" + i + "_Orbit1_TidalLock")
}
}
In text adventures you can create functions, so i
could be a parameter of a function, rather than in a loop. In fact, I would suggest doing it as a text adventure that uses hyperlinks, and then each planet could be an item, with various attributes and scripts asociated with it, and perhaps the stars could be rooms containing planets.
hegemonkhan
03 Sept 2016, 03:51as Pixie already demonstrated in his/her post:
the main issue is using the Scripts/Functions, which let you concatenate for your Object's name, your Attribute's name, and/or your Attribute's Value/Expression, such as:
- set ( http://docs.textadventures.co.uk/quest/scripts/set.html )
- do ( http://docs.textadventures.co.uk/quest/scripts/do.html )
- strings (String Data/Attribute Type) ( http://docs.textadventures.co.uk/quest/types/string.html )
- etc etc etc
and again as Pixie already demonstrated, for incrementing, numbers / displayment of numbers, using iteration:
- for
- foreach
- while
- etc etc etc
here's an example:
for (x, 1, 9, 1)
msg (x + ". blah_" + x)
}
// output:
1. blah_1
2. blah_2
3. blah_3
4. blah_4
5. blah_5
6. blah_6
7. blah_7
8. blah_8
9. blah_9
Sebastian2203
03 Sept 2016, 18:16I have grown too accustomed to gamebooks and I even though I tried text adventures before, they were confusing me with the sheer amount of possibilities and I also feared the combinatoric explosion.
I might give it a try again though, but anyway thanks for the help!