Editing a Choicescript_stats page - Advanced coding question


#1

In my latest game, I have three choicescript_stats pages in use via three buttons on the display screen.
I achieved this by editing the ui.js file in the web folder of choicescript.

The first two pages are purely informative, giving information about your character and your inventory.

The third page is for collector cards you can get in the game in packs. My problem is that I want the player to be able to go to the card page (the third choicescript_stats page) and open the packs there. I have it coded and it work well. The player can open packs and view their cards all in the choicescript_stats page. However… (there’s always a however) once the player closes the choicescript_stats page to carry on with the game, the next time they load the choicescript_stats page, all the variables have been reset.

Put simply, the variable changes made in a choicescript_stats page are not saved.

Now I need advice - should I edit ui.js more and stop it from resetting the variables when it exits the stats page, or should I find another way to display the cards.

For either solution, how should I go about doing that?


#2

There is one line I see which might be controlling the callback function. Line 46 (pretty sure, but I’m looking at a slightly outdated version of CS) it starts “scene.save”. Have you tried just deleting it? (I have no experience with java, so I’m just taking a stab in the dark here).


#3

I’ve attempted doing something like this in my game, but ended up giving up on it. I understand that choicescript saves the state of the game when you click the stats button, and reverts back to the saved state upon pressing the next button in your stat screen. I’ve looked around ui.js for a way to disable this, and also played around with variables as a way to save the changes made in the stats screen. If you figure out a way around this, please share


#4

I believe that may be the line I deleted trying to solve this problem, it seems to also disable choicescript saving the scene you left from when you hit the stat button


#5

@Reaperoa @Rob I tried editing and deleting that file, as well as playing with the other .js files but with no luck. Instead I’ve moved the whole ‘open pack’ section to another in-game page for the end of each day which works well, just not as smooth as I’d hoped.

There is a note in the ui.js file saying Todo: disable *choice in choicescript_stats (or words to that effect) suggesting that Dan Fabulich doesn’t want us playing with the files too much.


#6

I think it’s more about how decisions made in the stats sheet can’t carry back, and doing much of anything in it is kinda buggy, as there’s been no indication they have any problem with someone tweaking CS to fit their needs better.

Continuity wise, it might be better to handle it in game anyways, otherwise you might end up with someone opening a pack in the middle of a fight. :stuck_out_tongue:


#7

I have found a bug with openIng packs in game. Naturally, after opening a pack you want to see your cards in detail. So most people will click the card screen after opening a pack. However When you close the card screen, if you haven’t advanced (which most people won’t), it’s re-rolling the cards you got… Any ideas how I can get around this?

On further thought it seems this will be an error issue for any writer using the *rand command as a quick check of stats on that screen would re-roll the random number, allowing people to cheat, effectively. Like you say, check stats mid-fight to re-roll and get a better outcome…


#8

Would it be possible for you to add a couple variables after you rand card roll that would save the particular rand card roll. Say after the rand roll you could maybe set a simple boolean variable to true that lets you know you have a saved card, then another variable containing the number of you r rand roll. The player presses the card button going to the stat screen then returns, you add a couple if statements to the first few lines of your page to check if your boolean variable does indeed contain a saved card, if it does you bypass the rand roll, and again using ifs reset the boolean and saved rand roll. Does that make sense? Not sure if it’ll work though


#9

You, sir, are a genius. Will try it out now and let you know if it works.

Edit:
Nope. No good. Thinking about it more, I’d already tried it when naming the cards.
Not with a boolean, mind, but it’s the same principle. Rand a number. If number is x, set card_1 to “Whatever_name”.
This resets every time they press the Cards button :frowning:

Short of writing a message “Don’t click the Cards button until you get to the next screen” I can’t think of a solution. :expressionless:


#10

So am I to understand that when the stats button is pushed that it saves the state of a screen as if you just arrived at that screen or does it save the state at the moment the stats button is pushed. Because I can’t imagine why it wouldn’t work unless the former were true


#11

Okay, when you return from the stats screen, the game reverts to what it was before the most recent page was run, then runs the page again. This means that any *rand commands will be rerolled (in addition to at least one other small bug). There was some talk about fixing it with CoV, but it was decided that it was too small a bug to fix. The way around it is to roll stats up at least one page before you need them.

I’d recommend rolling up as many ‘packs’ as there are in the game at the start, saving each one to a variable (or set of variables), then calling them up when you need them. It would probably look something like what I have below (this would generate three packs of three cards, with each numbered 1 to 5):

*temp random
*create pack1
*create pack2
*create pack3
*set pack1 “”
*set pack2 “”
*set pack3 “”
*create pack_counter
*create current_pack
*set pack_counter 1
*set current_pack “pack”&1

*label add_card
*rand random 1 5
*set {current_pack} &random
*if {current_pack} < 100
-*goto add_card
*if current_pack = “pack3”
-*set current_pack “pack”&1
-*set pack_counter 1
-*goto pack_generation_finished
*set pack_counter + 1
*set current_pack “pack”&pack_counter
*goto add_card

This will roll up the packs, then, once the player opens the packs, you’ll ‘extract’ the cards with this:

*label first_card_extract
*if {current_pack} > 500
-You got the fifth card!
-*set fifth_card_counter + 1
-*set {current_pack} - 500
-*goto second_card_extract

This will be copy/pasted for each card in each ‘slot’, so you’ll do the same thing for the fourth through first card in the series, then do it again in the tens digit, then again with ones, replacing > with =. Then, at the end you’ll run:

*set pack_counter + 1
*set current_pack “pack”&pack_counter

Now, you’ll probably want to tweak the third line of the second portion (“You got the # card!”) so that is displays things in a neater fashion (probably using something akin to the language system in the CoV stats sheet/the inventory system in Zombie Exodus), but, besides cosmetics, that should be a watertight system to pregenerate packs.

It can also be further tweaked to include things such as different styles of pack, or other such things, or to ensure that at least one of each kind of card if able to be found.


#12

That’s a great solution, Reaperoa, and you’ve given me an idea to simplify it more. If a player opens two packs, the screen refreshes after the first and hence, saves. As such, I only need to pre-roll 1 pack and then the issue will be cleared. I can move the pre-rolled cards to the player and roll a new deck in the same screen. Sure, the re-roll will be different every time, but the player won’t get to see it until they open another pack.

It’s too early in the morning to try now, (5;45am) but when I can, probably lunch today, I’ll try it out.


#13

Just spent 30 mins playing with this and it’s progress so far. Not easy mind! First, I set it to generate a pack at the start of the game. Problem was, when a pack is generated, those cards were automatically added to your collection, meaning you get the cards before you open a pack. I had to separate the lines of code doing this, adding an extra 3 lines of code per card and it works. The first pack is perfect. However I now have another niggling error where every subsequent pack gives 3 “blank” cards. I’m sure it’s just one, maybe two lines of code from working. I just don’t have time to look and find it now. It’ll have to wait until tonight.


#14

I just looked at my code and I see the error. It’ll take a minute to fix tonight then it should be working perfectly!

(I keep all my code in Dropbox so I can read it anywhere - handy!)