Using *set Command with Invalid Expression


#1

Hey guys,

I'm working on a section of my game where the player can mine to earn gems using *rand.
I think I've got it all working, except for one line which is supposed to increase the item count by one in the player's inventory, where the items are stored as numeric amounts.

The line in question has the *set command below. All that stuff on the line works out, the problem is that a variable will not work with *set if it starts with a parenthesis, but I need that for proper concatenation.

Any ideas on how to have it accept that variable or ways around it?
Thanks.

Here's the part with the issue: (I use single space indents)

*if (Mine < 150)
 *sound Pickaxe1.wav
 Success!
 *line_break
 You found a [i]${Gem_size} ${Gem_purity} ${Gem_type}[/i]
 *set (("$!{Gem_size}"&"_")&("${Gem_purity}"&"_"))&"${Gem_type}" +1
 *choice
  #Continue mining
   *goto Go_mining
  #Stop mining
   *finish

An example of a possible output would be:

You found a medium chipped topaz

Then the variable Medium_chipped_topaz would be increased by 1.


#2

My understanding of *if commands is that they need their own *goto or *finish... I don't see either one attached to your *if command.

Here is an example:

 *if (name != "unknown") 
  #I am satisfied with my choice of name
   *goto sstart

I'm still a novice but looking at examples of *if in the wiki and tutorials, I always see one or the other attached to the command.


#3

Thanks for the suggestion. I'm very new to this too, and like you, I've recently read the wiki pages.
Directly above the code from my original post is this:

*label Result 
*if (Mine >= 150)
 You found nothing of use.
 *choice
  #Continue mining
   *goto Go_mining
  #Stop mining
   *finish

And this part works fine when I run it.
So the *goto and *finish commands inside the *choice command count as end points to the *if I guess.
I'm pretty sure the only problem with it is that single *set line. Seems I just need to find a workaround.


#4

The if command here is fine when followed by a choice.

@Swagmasta
Wish I could help but have never used a set command in that fashion.


#5

Thanks for looking! This is the first time I've dealt with a weird *set command too.


#6

This one's a bit beyond my skills with choicescript.

Is there anything in https://forum.choiceofgames.com/t/new-choicescript-features-for-programmers/8423 that's useful?

Also http://choicescriptdev.wikia.com/wiki/Concatenation on the wiki, but I presume you've read that.

Can you simplify it down and get it to work if you're just doing two of the variables?

I'd ask @Dfabulich on this one.


#7

I would need to see you list of gems and maybe come up with a work around for you or you may have to wait to one of the master coders can reply. My work around may not be pretty but should work, I am good at long coding lol.


#8

I've been messing with it a bit more after thinking about everyone's suggestions. I added a variable Gem_found

*if (Mine < 150)
 *sound Pickaxe1.wav
 Success!
 *line_break
 You found a [i]${Gem_size} ${Gem_purity} ${Gem_type}[/i]
 *set Gem_found (("$!{Gem_size}"&"_")&("${Gem_purity}"&"_"))&"${Gem_type}"
 *set Gem_found +1
 *choice
   #Continue mining
    *goto Go_mining
   #Stop mining
    *finish

The only problem now is that while I can overwrite the variable with a different data type (string to numeric,) I can't add a number to the string. I feel like I'm closer though!


#9

I am happy you are on the right track, little above my knowledge level, had to stretch my pea brain to grasp the basics. Really good with that but you get into combined var like your doing and it like trying to read Latin upside down in a mirror to me. :wink:


#10

Haha, honestly I feel the same way. This is my first experience with any kind of coding, and the only reason I can understand what I wrote is because I've been looking at it for so long and reading the Wiki a bunch :stuck_out_tongue:


#11

The first parameter in a *set statement can't be a string, but the second parameter can be. You can then set by reference as per the advanced choicescript guide.


#12

Awesome! Just did this and it seems to be working!

 *set Gem_found (("$!{Gem_size}"&"_")&("${Gem_purity}"&"_"))&"${Gem_type}"
 *set {Gem_found} +1

I'm not sure if that's exactly what you were saying, but close enough I think :slight_smile:


#13

Yup, that's what I meant! :thumbsup:


#14

Thanks, everyone! Now I can sleep! :sleeping:


#15

You could have something a little more readable using the array syntax, if you're happy to have a common prefix:

*temp gem_big_flawless_ruby 0
*set gem_size "big"
*set gem_purity "flawless"
*set gem_type "ruby"

*comment set (gem_big_flawless_ruby) + 1
*set gem[gem_size][gem_purity][gem_type] + 1