Just started a story, some general questions about coding


#1

Ok, this is my first game, along with my first post, but im having a little bit of difficulty with the coding.

One thing i would like to know about is 1.) How do you make it so npc’s will use the name the player chooses?

Another is 2.) how do you set up an inventory? like, i want to make it so players can pick up an object/and only be able to carry a certain amount of weight. Also how would you go about removing the inventory at certain points in the story?

My third and final question is 3.) how do you make it so you can select multiple choices? for instance, let’s say the players choosing hobbies

What do you enjoy doing?
*choice
#play video games
#play sports
#work out
#study
#play an instrument
#building

i want to make it so the player can choose 2 of the options and then move on in the story.

Any help is appreciated. Thanks
-Matt


#2

I’m not sure about the inventory, but as to the other two questions:

  1. For the name, you use *create name and *input_text name to create the name and then ${name} when you want someone to say it
  2. For multiple choices, the best way I’ve found is to just circle back and use the *hide_reuse option or create a temporary variable so that people can’t select it again.

#3

That helps quite a bit. Thanks a lot Kelasaar.


#4

@mattisgreat, an inventory system is not straightforward. It’s not possible to have arrays, per se, which is what you need for a flexible inventory system with no hard limit to the number of objects that can be carried. You pretty much need to set a hard limit, and the higher that limit, the more complex your code will be. For instance, if you’re going to allow three items, you’ll need three variables, and if you drop one of them, you’ll set that variable to the empty string. To then pick up another object, however, you’ll need to check all three variables to see if any are empty. That’s just for tracking the names of the objects.

If you’re also using weights of objects, you’ll need three variables to hold the weights, and associate them with the three variables containing the names. If you’re using any other values associated with those objects, such as monetary value, you’ll need three variables to hold them. If you associate some other attribute to each carried object, you’ll need three more variables for that attribute. You can see just from this that having many objects is going to greatly increase how many variables you need to have.

There are ChoiceScript (CS) commands that allow you to make use of similarly named variables as though they belonged to an array. Look at the *setref command, and do a search on that in the forum to see what’s already been said about it. You should also search the forum for “inventory” to see what’s been discussed about that topic already.

You could do something more flexible using JavaScript (JS), but that’s an advanced topic and not recommended if you have any hope of your game being ported to the Kindle. (I’m not sure about Android and iOS, but you probably want to avoid using the *script command all together if you want your game to be ported as a native mobile app and not restricted to running on the web.)


#5

This topic will show you another wau of offering more than one selection


#6

Some shameless self promotion here, but you can try out my visual code editor so you don’t have to do any actual programming. But it still allows you to implement custom code if you so wish!