Author Topic: Cataclysm of Chaos V9 (Text Adventure)  (Read 63870 times)

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos (working title)
« Reply #50 on: September 23, 2017, 01:53:27 PM »
Well, after working on a few different ways to rebuild the spell buying code, I've devised a solution that works elegantly. It will also make adding new spells significantly easier than the old system and will allow you to keep purchasing spells if you are inclined to do so.

Now I just need to re-add all the old spells to the new system. Just wanted to give a quick update on this, and once I've finished implementing it, and tested it to make sure it doesn't bork again, I should be able to get back on track.

EDIT:

Implemented and tested the new spell purchasing system and it works. Works so well, that I plan on using it to refactor the rest of my buy command code at a later date.

Alright, whew! Okay, now that the spell code is in, I'll finish up Section 4 (investigatables and boss loot), finish the last few journal entries for the sewers, and then likely release V4. Its likely that I'll do bugfixes for V4 when it is released, rather than do extensive testing beforehand, as it will take me a while to get down to section 3/4 in a playthrough, and simply intersperse the bugfixes with story/lore updates thrown in as well. I'm doing it this way for V4 as I already missed my release date for V4 and don't want people to have to wait too long for V4 now that I've addressed the buy command issues.

EDIT 2:

Finished Boss Loot for Section 4.

Once I'm done Investigatables for Section 4 and the last few Journal Entries for Sewer Section, I'll release V4. Barring any cataclysmic failures, I should have it released today (Sept 24)

EDIT 3:

Nearly ready for the release. Journal entries are in for sewers, and have one more investigatable for Section 4 to do. I'll likely again release bugfixes like I did for V3 release, rather than do the testing right away. I feel people have been waiting long enough for this release and want to get it out to players hands as quickly as possible.
« Last Edit: September 24, 2017, 04:11:57 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #51 on: September 24, 2017, 04:44:04 PM »
Released V4 and all links are updated. If necessary I will post bugfix updates for this one like I did for V3.

Release V5 will be focused primarily on adding a massive amount of lore/story to the game, a huge effort to refactor the codebase as some portions are getting somewhat unwieldly to maintain, and continue to hunt for ways to make the UI much better. 

Hope you enjoy, and am looking forward to any feedback anyone has, positive or negative of V4. Cheers!
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #52 on: September 24, 2017, 11:57:19 PM »
Found a logic error in one of the Section 4 boss loots, that affects the spellcasting system. I have fixed it and will release hotfix 1.

Also, I implemented a new quality of life system; you can now recast the same spell over and over again, to your hearts content... until you run out of mana or die that is XD.

EDIT:

I'll be releasing another hotfix shortly. I've determined a method of refactoring my attack and casting code, using function calls, while including the repeat last action code as well, and will make things a lot easier... particularly as I found a few errors in my newly added repeat action code in hotfix 1.

EDIT2:

Forgot to mention that Hotfix 2 got released yesterday.
« Last Edit: September 26, 2017, 02:54:38 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Cataclysm of Chaos V4
« Reply #53 on: September 26, 2017, 07:01:20 PM »
Will definitely check this out tomorrow. Have been super tired lately while adjusting to working full time again after being unemployed for six months but I'm starting to feel better again so, def tomorrow. :)

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #54 on: September 26, 2017, 10:07:08 PM »
Alrighty!

I'm continuing to putter along with V5 Release, which is primarily a code refactoring and an addition of a massive amount of additional, but optional, story and lore.
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline dave_erald

  • Sr. Member
  • ****
  • Posts: 262
Re: Cataclysm of Chaos V4
« Reply #55 on: September 28, 2017, 01:38:32 AM »
If I find the time I am definitely going to check this out. Congrats thus for Lord'o
-David R.V.

-GMT400 fan
-OPU Influencer

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V4
« Reply #56 on: September 28, 2017, 10:58:04 AM »
Good to see you're still moving along on this.

Quote
An alternative solution would be that if you flee from a drainer or boss, then the next monster encountered is a Tough, Quick, or Spellcaster. As you were using flee from object constantly to avoid drainers and kept getting them, this could potentially resolve your issue in a different manner. If you didn't have to use the command as often, would the command still feel wordy?

I really like your creativity on this problem. I wouldn't have even thought to try something like that.

I've looking forward to trying out the new additions shortly.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #57 on: September 28, 2017, 11:34:58 AM »
Cool! I'm still puttering away at refactoring the code for V5 release. Trying to only focus on areas that I know I will be added to in the future, and thus avoid getting stuck in the developer's trap of wanting to keep refining ones code. Existing code does work well, and performs its function elegantly... its just that adding new stuff to them is a chore. Thus, the point of the refactor is to keep the elegance of the code, but make it easier to add stuff to it; to aid workflow and the like.

Well, I also figured out a way how to now shorten flee from target, to just flee; it will be in V5.

EDIT: Turned out my flee code isn't working properly and still gives a drainer if fled from a drainer. I'll add this to the list of systems to refactor.
« Last Edit: September 29, 2017, 01:33:55 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #58 on: September 29, 2017, 11:21:42 PM »
Uploaded Hotfix 3 for V4. While testing out my refactored flee code, to ensure that it was working, I discovered a major syntax error that prevented the purchasing of LV7 spells and found major errors in the turn script (called every turn) that controls the majority of buffs in the game that prevented the buffs from activating at all.

So...

It includes many of the refactored code and new items that I had intended for V5, but felt that due to the nature of the errors a hotfix was necessary... as I'm only about half-way through making my V5 release, I figured getting a fixed game out pronto was higher priority.

So, the changelog in the zip file (mediafire/attachment to first post) includes the changelog of bugs fixed and new features / refactored code meant for V5.

Anyway, hotfix 3 is out, and I'm going to get back to working on V5 again, and hopefully no other major errors are found in the meantime.

EDIT:

Also, flee code now works properly, and will give you either a Tough, Quick or Spellcaster when you flee a drainer or boss.

EDIT2:

I'm going to shelve monster and player descriptions for next release. I'm running into huge issues keeping code redundancy down, and its just delaying V5 release, with the extended lore. So, will plan for descriptions to be in V6 release instead.
« Last Edit: October 01, 2017, 09:42:42 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V4
« Reply #59 on: October 03, 2017, 03:20:37 AM »
Hey, I took a quick look through your most recent update. I saw a few opportunities for improvement. Early on when I started programming, I often had large nested if/else and switch/case blocks. Often blocks were copied/pasted, and values updated. I'm seeing the same sort of pattern in your code. It's an easy way to start out. Simple, works, and you get something you can see quickly. Over time, with more experience, I moved to a different approach, driven by little inconveniences that added up over time.

One inconvenience was the repetition of values. You might check the players money against the price of an item in an if statement, and then later subtract the price from the player's money in another statement. The price of the item is duplicated in the code. If you ever change it, you have to change it in both places. If you forget, or make a typo, you end up with a bug. It's a simple update yes, but over time it gets very tedious. Worse, if you have sell code, the sell price might be different, and in a completely different section of the code, making it easy to forget about, and harder to find to update at the same time. It's best to have the values defined in one place. You'll sometime hear the DRY principle: Don't Repeat Yourself.

Another inconvenience is the duplication of copy/pasted bugs, that require fixing in multiple places. This is also relevant for a design change. Perhaps a new feature requires you to update code that was copy/pasted multiple times, and now needs to be fixed for every occurrence. Let's say you wanted to add an item or skill to the game, that allows players to charm shop keepers, and have them reduce their prices by some amount. To implement that, you'd need to update all price checking and purchase code. A major pain if it has been duplicated 50 times. This is another application of the DRY principle, but to the code itself, rather than the data values.

Yet another inconvenience is having to update code in multiple places when you add a new item or feature. Perhaps you add a new weapon, with updates to purchase code, sell code, and attack code. All in different places. It would be nice if adding a new item required changes to only one place in your source.

There's also the slight inconvenience of code bulk. If you have a ton of copy/pasted code, it's quite a bit to scroll through. It slows you down while navigating the code, and adds to the mental load of working on it. It's hard to quantify this effect, but I feel there's just something nice about having all your functions fit within one screen of code.

I can show you how to drastically cut down on code bulk, while making it easier to make changes, avoid bugs, and add new items and features. And the best part is, you're probably already applying most of the principles to do it.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V4
« Reply #60 on: October 03, 2017, 05:54:13 AM »
Oh, and a bit of feedback. For the spellbook, typing "1st", "2nd", "3rd", "4th", etc. is kind of annoying. It'd be much easier to just type "1", "2", "3", "4", etc.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V4
« Reply #61 on: October 03, 2017, 12:43:12 PM »
Yes that is a lot why I'm doing the refactor for V5, to reduce code redundancy and try to replace the massive numbers of nested ifs with function calls. However, I'm also trying to avoid spending all my time refactoring, which is a trap that some developers fall into... certain sections of the code base I likely won't touch again, so I figured I'd avoid refactoring them. One of them is the prices of items (exception being the recently changed spikes); though I will have to change the sell code for armors/shields when they have spikes added to provide the value of the item with spikes.

The issue with most of these is the problem of "how do I avoid it?" JavaScript / Quest lacks many of the features that C++ has to handle these concerns. Take variable declaration; in C++ you can declare local variables in a function, member variables of a class, global variables, and variables local to int main(). In quest, you can only declare local variables in a function call OR member variables; you cannot declare variables into the "main function" and you cannot declare global variables. You also cannot declare constants. And in C++, constants are great for declaring a variable once, setting its value, and then copying it to multiple places and then when you need to change it, just change it once in the constant and its applied everywhere. Can't do that here.

So the only alternatives left are local variables in a function call or member variables of a class. The majority of my variables are member variables of a class... usually a dummy class that does nothing by itself, but is used to store all your variables you need. Its annoying, and it clutters up the class, but its also the only way to do it other than local variables in a function. A lot of the other things that you take for granted in C++ are not found here in Quest. You are very limited in the kinds of function calls you can perform and the return value portion of a function call is EXTREMELY finicky.

Thus I've been forced to figure out workarounds to many of these problems... code replication is unfortunately one of the symptoms of that. I've managed to greatly reduce it in this refactor, but there is obviously tons more left to do. Such is life. Now to address what you specifically said.

Prices of items either have to be typed in or stored in a member variable. And debugging a class when it has over 100 member variables is a real chore. Also, the interface gets really cluttered when you have too many objects. Also, the quest engines chugs if you have too many member variables and classes. So I try to keep this down by declaring the value as a numerical constant (as compared to a variable constant, as you can't do those). In some cases I will use temporary variables, but I try to, again, use them sparingly. If quest / javascript allowed me to do variable declaration outside of classes and functions I would do it, as that would make my life immeasurably better, but I can't.

Again, trying to reduce code replication with function calls is great, but I don't want to spend all my time fixing code that I do not forsee myself adding to in the future. The code I have refactored is code I will be working with quite a bit in the future. But things like buy/sell code or player update scripts, I won't likely touch again, and thus refactoring them would make the codebase look nicer but not really improve my workflow at all.

That is true if I intended to add a new weapon. I do however intend to add new spells, which is why I completely overhauled the spellcasting system. With the old system, I had to place information in about 12 different places. Now, I only need to put it in 4 places. So I definitely agree making it less replicating for adding stuff is important!

Well, I personally don't have any issues reading my code. So having it take up three to four screens of code has no impact on the readability. If there was more than one person working on the code, then I'd strive to have code blocks more concise and have brevity. But as that isn't the case, I code in a way that is most readable to me and has all the needed logic present.

Most of the refactoring is actually completed for V5. Almost all of the major systems have been refactored now, that I intend to add to or manipulate for Sections 5, 6, and 7. Now I'm working on the lore side of things.

Also, thanks for the feedback on spellbook. I found it a bit wordy myself, but didn't get around to changing it.

EDIT: I'm getting bogged down with writers block for a couple days now in doing lore, so I think I'm going to have to shelve it for the time being. I'd like to do recurring characters for the lore, particularly adventurer journals, but can't quite figure out how to do so. So, I'm going to release V5, and start working on additional gameplay features and do the lore whenever I can overcome writers block.
« Last Edit: October 03, 2017, 03:25:34 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #62 on: October 03, 2017, 03:44:23 PM »
V5 of CoC is uploaded now.

Since I ran into some horrible writers block for V5, I will be looking into ways to get around that, to hopefully get some good lore in for V6 release. I shelved it because its been a few days since I've gotten anything done on the game, and figured I can always do the lore later as it is technically optional, but does help to immerse the player better; not necessarily crucial for a beta release, but very important for a late beta or close to final release.

Enjoy!

Also, I have found that any feedback on the game has been very crucial, to help me make it better so if anyone wants to post some more feedback, please do so!

EDIT: Noticed I missed adding rename item command, so I'll focus on a hotfix 1 for V5, with any typos, minor UI improvements and bugs I encounter, included in it!
EDIT2: Playtesting my game a fair bit and have noticed several areas for improvement that will be included in the hotfix 1 for V5.
« Last Edit: October 03, 2017, 06:38:26 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V5
« Reply #63 on: October 04, 2017, 12:52:59 PM »
Quote
However, I'm also trying to avoid spending all my time refactoring, which is a trap that some developers fall into...

Touche  :-[  :P


You're right, JavaScript certainly works a lot different from C++. It doesn't always have the same features, though with that said, there are often parallels to many of the patterns. Some require quite a bit of creativity, or newly introduced JS features.

Quote
Take variable declaration; in C++ you can declare local variables in a function, member variables of a class, global variables, and variables local to int main(). In quest, you can only declare local variables in a function call OR member variables; you cannot declare variables into the "main function" and you cannot declare global variables.

I'm a little uncertain about this "main" function you speak of. Is "main" a real function, or just all the code at global scope? JavaScript doesn't usually have a function named "main", though if it did, I would assume it would work the same as any other function, as would its local variables. I suspect "main" is just a way of referring to code at global scope. In that case, any local variables would be global variables, and your comment starts to make a bit more sense. Is there any Quest documentation on this?

One thing I noticed is Quest seems to segregate the JavaScript code into separate XML tags in the file you provided. I'm wondering if it might also do some kind of isolation between the script components. That could explain a lack of global variables, or at least access to them.

Quote
You also cannot declare constants. And in C++, constants are great for declaring a variable once, setting its value, and then copying it to multiple places and then when you need to change it, just change it once in the constant and its applied everywhere. Can't do that here.

Const seems to be a feature that JavaScript was lacking for a long time. The ECMA2015 standard includes const. Since this is fairly new, it might not be available in the Quest environment, or perhaps it is but documentation is old and says otherwise. Is there a section of the Quest documentation that addresses consts? If the game is running in a browser, it might depend on browser support. In particular, IE11 supports const, but not older versions of IE. The version table at the bottom of the link lists version requirements for other browsers.

Quote
A lot of the other things that you take for granted in C++ are not found here in Quest. You are very limited in the kinds of function calls you can perform and the return value portion of a function call is EXTREMELY finicky.

Is this personal experience, or documented restrictions? I'm curious what the restrictions are. I know C++ has had a lot of restrictions on return values. They have been slowly eased over the years as compilers have gotten smarter, and are able to efficiently handle more cases. I've generally assumed that JavaScript has a simpler model with fewer complications, and so fewer restrictions. Though again, JavaScript in the context of Quest might be a little bit different.


Seems like you've managed to work around quite a few issues.


Quote
Prices of items either have to be typed in or stored in a member variable. And debugging a class when it has over 100 member variables is a real chore. Also, the interface gets really cluttered when you have too many objects. Also, the quest engines chugs if you have too many member variables and classes. So I try to keep this down by declaring the value as a numerical constant (as compared to a variable constant, as you can't do those). In some cases I will use temporary variables, but I try to, again, use them sparingly. If quest / javascript allowed me to do variable declaration outside of classes and functions I would do it, as that would make my life immeasurably better, but I can't.

Yikes, that does sound messy putting that many variables on an object. Have you used arrays at all? I think arrays of objects could simplify some code. That would reduce the number of variables on each object, and perhaps simplify naming. Where would you put variables if they weren't part of a class or local to a function? I tend to avoid temporary variables too. Less clutter if you can use an expression directly, though if it's an expensive calculation, it may make sense to cache it in a temporary. That's pretty rare though. If you are using temporaries somewhere, it might be a good place to extract code into a function.

Quote
Again, trying to reduce code replication with function calls is great, but I don't want to spend all my time fixing code that I do not forsee myself adding to in the future. The code I have refactored is code I will be working with quite a bit in the future. But things like buy/sell code or player update scripts, I won't likely touch again, and thus refactoring them would make the codebase look nicer but not really improve my workflow at all.

That's a very practical consideration.

Quote
That is true if I intended to add a new weapon. I do however intend to add new spells, which is why I completely overhauled the spellcasting system. With the old system, I had to place information in about 12 different places. Now, I only need to put it in 4 places. So I definitely agree making it less replicating for adding stuff is important!

Wow! That would be so hard to keep track of.


Lore is fun. That can certainly add a lot to a game.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #64 on: October 04, 2017, 07:07:11 PM »
Well, I just know that some of the worst gaming blunders or getting stuck in development hell is generally a result of constant refactoring or redesigning when something doesn't need to be redesigned. Not pointing fingers at anyone here in particular, rather when I think of that I think of a guy named Josh Parnell, "trying" to make a game called "Limit Theory". He seems to be a very talented individual, but there were numerous instances, before he burned out, of him getting caught in the constant refactoring of the code. So, I learned from his mistakes by just refactoring code I know that I will be added to in the future and know that the refactor will greatly aid my workflow. Like in the example of adding spells with the 12 step process, it would take me about 2 hours of coding to add 6 new spells. With the new system of about 4 step process, it took me all of 10 minutes to add 2 new spells. So, that is a great example of where refactoring greatly aided my workflow. But, as there are other places where things could be refactored, but won't aid my workflow because I don't intend to add anything to it, there wouldn't be much point in refactoring, other than to make the code prettier. So that's my personal view on things. I definitely agree that learning to do things better is a good idea, and I will utilize a lot of that for future projects, but for things that aren't needed to be refactored, I'll leave them alone!

===

Well, in C++, when you learn to initially code in the console window, it has you code within int main(), which is implied to be the main function. So when you do a function call, it returns a value to another function call, but eventually control is given back to int main() and the program ends when int main () reaches a return statement, and returns control back to the OS. At least that's how my old C++ textbook explains it.

Well no, actually in console coding I found you can actually declare things outside of int main () which would make them a global variable, usable by any function or code block within the entire program.

I've actually not taken a look at the raw code in the renamed zip file, so can't comment on that.

===

Well, being that Quest only recently got an update (August 2017), after it went with about 1-2 years without any updates, I doubt it includes the const feature from the 2015 update to JavaScript. I've certainly not seen it anywhere mentioned in the documentation or when using the program itself.

===

Both. The documentation is VERY brief on the usage of function calls (they only explain how to use string-based function calls), and I only learned how to use them by trial and error, as they don't work exactly as a C++ function call does. I'll give a basic example I ran into:

Buy a spell that cost 100 soul shards. You start with 300 soul shards. Set to return a value of type integer. Formal parameter and argument is an integer. Formal parameter takes your current soul shards, parameter being called CurrentShards:

CurrentShards = CurrentShards - 100
Return (CurrentShards)

So if you do it like this, the function call BORKS, and returns no value, and instead sets your current shards outside of the function call to 0, and spews an error about the function call not returning a value. However, if you do it like this:

Return (CurrentShards - 100)

Then, it will properly subtract 100 from 300, and returns a value of 200 and then assigns 200 to your actual current soul shards outside of the function call; also won't spew an error about returning a value.

In C++, either way of doing things would properly return a value of 200. But here, it will only work properly if you do the subtraction inside the actual return variable. So as a result, most of the time I don't bother with the formal parameters and just take the actual value that stores the soul shards and has it subtracted in the calculation and gets applied to the value storing the soul shards outside of the program and also don't bother with return values. Its very strange.

===

The program doesn't allow for arrays as far as I can tell. The closest thing to an array here are Lists or Dictionaries. Lists can store a list of strings or objects (which is something you can technically do in C++) but cannot store variables or values unless they are a string or an object. Dictionaries I think work something like a mini-database and requires you to use Keywords to access values in a Dictionary. Unfortunately both Lists and Dictionaries have terrible documentation, and even asking for help from other developers on the Quest Forums, I've still not managed to get Lists to work properly, and haven't attempted to use a Dictionary. If I could figure out how to use them, it would make doing Lore entries significantly easier and listing off purchaseable spells, but my current methods of doing both are sufficient for my needs; just that Lists could likely make it a lot easier... if I could figure out how to use them.

There is a consistent theme with the documentation; it isn't well documented, and most of my workarounds have been devised by trial and error and getting help from the Quest Forums... I've tried to use the documentation but its not very helpful. So learning how to do things in Quest has been slow for me.

Well, the documentation is useful if the type of text adventure you want to do is something like Zork. But if it is more complicated than Zork, which my game is incredibly more complex, then its terrible for getting assistance from.

===

Lore is fun! However I want some consistency, and some recurring characters, otherwise the player asks the question, "Why should I care about all of this?". So need to figure out some ways of both overcoming writers block but also devising interesting mini-storylines that are worthwhile to read and help to immerse players more into the game!

« Last Edit: October 04, 2017, 07:15:41 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V5
« Reply #65 on: October 05, 2017, 07:12:08 AM »
Since Quest uses JavaScript, and JavaScript has things like arrays, const, and globals built in, maybe just try using them and see. That might be why the Quest documentation is minimal. Maybe they expect you to just go read JavaScript documentation.

Code: [Select]
// Array of ints as a variable
var arrayOfInt = [ 5, 10, 15, 20 ];

// Array of objects as a const
const arrayOfObjets = [
  { name: 'Sword', cost: 500, damage: 10 },
  { name: 'Two Handed Sword', cost: 1000, damage: 20 }
];



Quote
So if you do it like this, the function call BORKS, and returns no value, and instead sets your current shards outside of the function call to 0, and spews an error about the function call not returning a value.

That error might be telling. JavaScript is case sensitive, and "return" should be all lowercase. Plus there is no need for parenthesis around return values. Maybe there is a syntax error in the return statement which is causing the error, and so it's not recognizing that line as a return statement, thus giving an error about the function not having a return statement.

If a function does not have a return statement, you'll probably get some default null or 0 value if you try to assign the result of the function to a variable.



To tackle a deeper concept, I'm not sure if you really want to return an updated amount of money. The purchase code has two side effects in the successful case, but only one return value. The side effects are: removing the cost of the item from the player's money, and giving the player the purchased item. It seems a bit weird to divorce the two operations, and require the caller to perform one of them. It might be better to wrap the code in a method with no return value, but which handles both side effects internally. If you pass in some reference to the player, and the item they want to buy, the method should be able to both remove money from the player, and give the item to the player. It's also the right place for any error checking like seeing if they have enough money, or have room in their inventory to hold the item.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #66 on: October 05, 2017, 12:27:46 PM »

At this point, most of my coding needs are met with the UI, so I see no point in bothering with messing with JavaScript. It'll just be time away from developing, like pointless refactoring.

===

Okay, I'll reiterate. One way worked and one way didn't and the difference between the two code snippets is a minor change. Here is the original code (This way borked):
{
  ShardCost = 100
  CurrentShards = CurrentShards - ShardCost
  Spellbook.KnowArcaneZap = true
  return (CurrentShards)
}

(This way worked):

{
  ShardCost = 100
  Spellbook.KnowArcaneZap = true
  return (CurrentShards - ShardCost)
}

It is a minor change, in the syntax. One way does nothing, spews an error, and nulls my Soul Shards. The other properly subtracts 100, and returns 200 to my soul shards and doesn't spew an error. The only change I made to the function call was moving the subtraction into the return value, and that made it work. Any other way of doing the function call borked. Explain why.

===

Honestly, I just use function calls to make the code easier to read at this point or reduce code redundancy. I'll likely tackle a something with a deeper concept if I run into a more complicated problem in the project OR in a different project.
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V5
« Reply #67 on: October 06, 2017, 04:11:14 AM »
Can you include the calling code and function signature too. And is this copy/pasted, or retyped code? I ask because these errors are often the result of very hard to see typos.

I'm noticing there is no "var" before any variables, so they seem to be declared elsewhere, possibly as function arguments.

The problem is most perplexing. I feel there is something missing here.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #68 on: October 06, 2017, 01:02:36 PM »
In Quest there is a button in the interface called "Code View". I clicked on it and copied verbatim all the code in the function call itself.

ShardCost is a local variable, and yet it is odd that it lacks the variable type before it; ie = int ShardCost; as a variable declaration within the function body.

...

SpellPurchase(player.SoulShards)
msg ("You purchase the spell and your current soul shards are = " + SpellPurchase(player.SoulShards) + ".")

...

The calling function is SpellPurchase. The code I showed before is all the code within the function call.

Then the msg afterwards tells the player what their current soul shards are. The SpellPurchase(player.SoulShards) is the value returned by the function call.

///

The calling function has no issues and nor does the msg afterwards, if the code in the function call is of the version that worked, it will properly display in the message that your current soul shards are now 200. Otherwise, it sets current soul shards to 0, and spews an error.

There is no other code present to show you. I'm not holding anything back. Unless there is code hiding elsewhere in the codebase, outside of the function call or the calling function, then all the code presented is all the code.

EDIT: I forgot to mention that it was part of an If-Else statement.

If (Spellbook.KnowArcaneZap = false) then:
{
  ShardCost = 100
  Spellbook.KnowArcaneZap = true
  return (CurrentShards - ShardCost)
}

With no else. Thus if you knew the spell, nothing would happen.
« Last Edit: October 06, 2017, 01:04:34 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V5
« Reply #69 on: October 06, 2017, 03:55:49 PM »
Interesting. You seem to be calling the function SpellPurchase twice. What would happen if you eliminated the first call, so only the second call embedded in the msg call was used?

Looking at your if statement, it looks to be doing an assignment of false to Spellbook.KnowArcaneZap, rather than a comparison. In JavaScript you need a double == sign for comparison. Though the "then:" part is not proper JavaScript syntax. Something weird is going on here. Is this a non-JavaScript code display? In VB syntax, a single equal sign would perform comparison, so that if code could make sense using the syntax of a language other than JavaScript.



Syntax oddities noted above aside, have you considered a function that works like:
Code: [Select]
SpellPurchase(player, spell)
msg ("You purchase the spell and your current soul shards are = " + player.SoulShards + ".")

Here the player object is passed to the function, allowing the function to update both the spell book (assuming the spellbook belonged to the player object, though I suspect this might not be true in your code), and the player's money.

There is no second call in the msg statement. It simply outputs player.SoulShards, which should have been updated by the previous call.



As for int ShardCost;, that would be valid C++ syntax yes, but not valid JavaScript syntax. JavaScript would use var ShardCost; to declare a variable. JavaScript doesn't use static types, so there's no way to declare a type when you define the variable.

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #70 on: October 06, 2017, 07:31:20 PM »
Nothing would happen if I eliminated the first one. In the UI, the function call itself looks quite different than the one in the msg. It looks the same in code view, but if I omit the first one, then no function call occurs.

The "then" may or may not be present I can't remember. I deleted the function call when I found out it didn't do as expected and moved on. All I know for sure was that it was a if-else statement with only the if code block filled with code.

Spells are coupled with the Spellbook. Technically they do not exist, they are just string placeholders, with a specially designed series of functions that actually are the spells. So when you type cast arcane zap, the spell arcane zap is just a series of string variables and then in a different spot, the string is used in a switch statement to determine the correct numerical code to be used. Its a very complex and difficult beast, but it works.

Spellbook is a separate object, that is added to the player's inventory at game start.

Yeah, I dunno. I'll have to think on why one way worked and the other didn't some other time. Going out for supper with a friend, so can't type much at the moment.

EDIT: After a bit of work, I determined how to do my Bad Traits system for my game, and implemented them for the first 5 investigatables (corpses excluded, so that you can always search those corpses for lore!)
« Last Edit: October 07, 2017, 11:04:52 PM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V5
« Reply #71 on: October 13, 2017, 09:21:28 PM »
Well, I'm nearly done with V6 release. Due to real life issues, trying to work on a feature I want to implement in CoC but in a different "driver" text adventure, and very complex to code features, this release has taken a lot more time than expected.

Still left to do is:

1) Ambience system; won't be using a timer as I've found in my testing that timers will screw with the UI and user inputs. So it'll be implemented as a turn script instead. What I mean by screwing with, is that if a timer occurs any text will appear, and not scroll the screen down, forcing the user to do it, whereas other text will scroll the screen. Secondly, if the player is typing in a command during the time when a timer activates its script, it will not accept user input until they scroll the screen, which is understandably frustrating.

EDIT: Apparently there is a way to get it to scroll to the bottom, when a timer occurs, so perhaps I can keep it as a Timer after all.

2) An insect hive interactable... so that the player can acquire the phobia to insects via a trap, and not just via death.

Will likely release V6 tomorrow (today is 13th)

I'll save the other features of V6 (on my list of things to do for V6) for V7 instead, as there are some significant changes made in V6, such as Boss Abilities, Time System, Positive/Negative Traits and of course, quite a few logic errors introduced by the V5 refactoring of the codebase.
« Last Edit: October 14, 2017, 02:01:33 AM by lordpalandus »
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V6
« Reply #72 on: October 14, 2017, 03:15:10 PM »
Updated to V6 Release. Lots of new features and bug fixes. Again, sorry for the long-development time for this release (relatively compared to previous release schedules) and hopefully the next release will take less time!

Enjoy!
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline lordpalandus

  • Banned
  • Hero Member
  • *****
  • Posts: 825
Re: Cataclysm of Chaos V6
« Reply #73 on: October 16, 2017, 02:14:30 AM »
Updated the game to Hotfix 1, V6 Release.

Fixes a few errors, and now the recast spell system fully works properly. Also redid the commands for look at spellbook and look at satchel as they somehow conflict with my custom look at monster or look commands; renamed to read spellbook or search satchel.

Also implemented specially tailored boss battle rooms for each boss, to make the fight a big more thematic and climatic.

Now I'll work on V7 proper, and hope no other major errors occur in the meantime.

Again, always like feedback; enjoy!
Currently working on Cataclysm of Chaos, Remade.
Link to OPU page = http://forum.outpost2.net/index.php/topic,6073.0.html

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Cataclysm of Chaos V6
« Reply #74 on: October 16, 2017, 07:32:18 AM »
This doesn't look right. Saw this after ascending back to the city. I had fought one fight, and then looted the room. After which, I typed "ascend".
Quote
You find a stairwell leading down, and thus can enter the sewers from here.
You enter a diamond-shaped room. It's brick walls are stained brown, by years of fecal matter. It's ceiling is shored up by wooden beams, barely keeping the sagging ceiling from collapsing entirely. It's wet floors slope towards a center point in the room, where a sewer grate empties the sewer waters from the room. There is a massive wasp hive here, that appears dead, as you don't see any wasps coming out of it. There is a large iron-bound chest here.

You discover a shrine!
It's health is currently = -13.


> setup camp
You cannot setup camp while under attack.

> attack
What type of attack will you perform:

(strike) [Highly accurate, but low damage attack]
(overpower) [Highly damaging, but low accuracy attack]
(bash) [Bashes target quickly with your shield; low damage but high accuracy]
(slam) [Slams target with your shield; high damage but low accuracy]
(backstab) [Sneak attack a target, if conditions are met; else, turns into attack.]
(cancel) [To abort your action for whatever personal reason you have.]

Error running script: Error compiling expression '(player.TotalAccuracy + getrandomint(1,10) + player.TempAccuracyModifier) > (object.Dodge + getrandomint(1,10))': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'


Would you like to attack Spellbook again, with the same type of attack? (yes) or (no)

The bee hive loot could probably use some minor rewording. The grammar seemed a bit off. The description was also not so convincing or immersive. Not sure "bored" applies to a bee. Also not sure why the bee had such an easy time stinging, only to be suddenly and easily killed when it decided to stop.


Also thinking the character creation needs some slight simplification. The "are you new yes/no" prompt, and "begin" seem a bit overly verbose. I'm thinking the surface prompt should just include a note about typing "help" for a list of commands. It's fine if the prompt is repeated indefinitely the whole game. It needs to prompt the player to input a command anyway.
« Last Edit: October 16, 2017, 07:40:00 AM by Hooman »