My coding questions


#1

I sincerely hope no one finds this a problem, but it just seems easier for me to keep all my questions in one thread for my future reference. And here’s my first question.

I’ve got contenteditable.html open from the editor sub-folder, and I copy & pasted one of my scenes. I had created & set a variable for arenavisit (a true/false setting) in my startup.txt, and when I run my arena.txt through the contenteditable.html, it stops at the arenavisit check (for true/false setting) and tells me its a non-existant variable…which it is, in arena.txt, but I originally set it in startup.txt.

What do I do? It wont let me check anything passed that line.


#2

If your just running arena.txt through it then it wouldn’t run start.txt to set the variables. May I ask why your using contentedible.html I’ve never had to do that to test the game. I just open index.html


#3

From the brief while playing with contenteditable (edible? :D) I found it useful for when you want to test a particular snippet of your code without having to mess with existing variable structure. It’s like a code editor in the browser. Not sure if it becomes irrelevant since the startup thingy was introduced, assuming less people are using mygame.js now. I think it worked with browser other than Firefox, too - I used Opera back then, which is not much usable for offline tests.

But yeah, it didn’t seem to pass variables around with more than what’s in the one txt you’re working on. I suppose you can always paste in from the other file the bit where you define all the variables needed to make them local?


#4

I think contenteditable is something Dan’s been slowly working on, I would imagine it’s still incomplete at this stage, you’re best testing your game directly through running index.html.

Or if you really want to use it, you could try including ‘mygame.js’ as a script source in the header - but that’s assuming you’re using mygame.js, not the *create command.


#5

@Nocturnal_Stillness This is my first CoG I’ve ever made, so I’m just trying a little of everything to see how they work.

@CJW I’m using the *create command, and I have no idea how to use mygame.js.


#6

I tried 2 different methods of coding so far. The first was to put all the choices & goto statements at the beginning of startup.txt, with all the blocks of in-game text at the bottom…seemed to work well. The second time, I tried doing it all branch-style (for lack of knowing the proper term) with the choices leading straight to the text.

Turns out I suck at the second way I tried doing it. The first way, I can’t be certain as I’m a beginner at this, but I feel like there must be some way to tighten it up a bit. Can I have a coding pro volunteer to have a look at it? Its just character creation and all the pre-game stuff I’ve already DropBox’d for all to see, so there are no spoilers in it.


#7

Alright, well that second way (indented, couldn’t think of the word yesterday), still isn’t working for me. I blame myself, not the tool. Back to my original way of doing it.


#8

*choice
     #Click me
        This is how you do it!
        *page_break
        New page...
        *page_break
        Another choice!?
        *choice
            #What is this madness!?
               Well done. You win.
               *page_break
               Have a medal!
               *finish
     #Or me
        Different text!
        *page_break
        End of game.
        *finish


#9

Thank you, but I’m also having trouble with choices within choices and if statements. Its almost absurd how much I remember Basic from nearly 30 years ago (which is quite similar) and I can envision how I’d write it that way.

I think I need a voluntary private mentor to answer my questions as they come up. I’m gonna feel bad hogging the board with questions that’ve probably already been asked a dozen times.


#10

Feel free to message me - but keep in mind that if you post it publicly others with the same problem can learn too :slight_smile:


#11

@DaveDPF This is your thread! Don’t feel bad about ‘hogging the board’ there’s no such thing. Everyone needs to learn. It can also be better if you post publicly, that way if one person can’t answer the question someone else can, and other people in your situation will also learn things.

I have issues with choices within choices. I just use the *goto command so I don’t need to deal with lots and lots of nested choices and trying to keep track of my indentations.

I also had huge issues with if statements and trying to wrap my head around the logic when I first started on choicescript. It was so bad that I tried to do everything in my first game to avoid them. I think I had one small section with an if statement and it took a ridiculous amount of time for me to write it.

I remember writing my first ever text adventure in Basic from a book I borrowed from the library. It wasn’t a very good game, or very long either, but I was determined that I was going to try. Choicescript is just so much better. :slight_smile:


#12

Yeah, Choicescript is brilliant once you get the hang of it. Dan Fabulich … ha, more like Dan FabuLOUS.

I’m here all night, ladies and gents. … Try the veal.


#13

You guys and gals here at CoG really are pretty awesome. Thanks for the encouragement, I truly appreciate the support…sure beats seeing replies that just say RTFM. :wink:

Rock on, my fellow CoGers!


#14

In an effort to avoid anything even slightly spoiler-ish, I’ll replace some text here with x’s, but the error I’m currently getting is Expected option starting with # (at the line that starts “That’s odd”)…


*label examine
xxxxxxxxxxxx.

xxxxxxxxxxxx.
*if Brains > 2
  In particular, you notice xxxxxxxxx.
*label bas_relief
xxxxxxxxxxxx?
*choice
  *hide_reuse #xxxxxxxxxxxxxxx.
    xxxxxxxxxxx.
    *goto bas_relief
  *hide_reuse #xxxxxxxxxxxxxxx?
    xxxxxxxxxxx.
    *goto bas_relief
  *hide_reuse #xxxxxxxxx?
    xxxxxxxxxxxxx.
    *goto bas_relief
  *hide_reuse #xxxxxxxxxxxx.
    *goto bas_relief
  *hide_reuse #xxxxxxxxxxxx?
  *if Brains > 2
    xxxxxxxxxxx.
    *goto bas_relief
  *else
    That's odd, xxxxx.
    *goto bas_relief
  #Nah, I'm done here.
    *goto arena_entrance


#15

When using *if statements, you need an *elseif for every option that isn’t the last option (which is *else).

*if blah = 0
Zero.
*elseif blah = 1
One.
*elseif blah = 2
Two.
*else
Whatever comes after 2.


#16

You might have replied while I was editing my post, please check again? Where did I go wrong with my if/else lines? (and I know it isn’t indenting properly, can’t seem to post screen caps).


*if Brains > 2
xxxxxxxxxxx.
*goto bas_relief
*else
That's odd, xxxxx.
*goto bas_relief


#17

You don’t need elseif or even else. I just use ifs.


#18

You can put code in the forums by doing

< pre>
Code here
< /pre>

with no space between the < and the pre>

like so


Code here

It will preserve your formatting.


#19

You don’t need to use else? o.O My whole life has been a lie.


#20

You don’t need to use it. If you cover every option with an if statement, then you don’t need else, since there’s nothing else left.

Else can be useful of course, for everything you’ve not covered.

It’s probably bad coding of me not to use it, mind you.