Sponsored Content
Full Discussion: Some questions for mini game
Top Forums Programming Some questions for mini game Post 302474770 by Corona688 on Thursday 25th of November 2010 10:38:06 AM
Old 11-25-2010
There's a simple trick to printing on the same line: Don't print newlines, print carriage returns instead. That will return it to the beginning of the line, instead of moving to the next line, without resorting to things like ANSI escape sequences.

Of course you have to be careful to always overwrite everything that was printed last time, otherwise you'd get a countdown like 10,90,80,70,60,50,40,30,20,10 -- not what you wanted at all Smilie

And since you're not printing a newline, you either need to flush the output all the time, or print to the unbuffered-by-default stderr (or cerr) stream.

Code:
int n;

for(n=10; n>0; n--)
{
       // %2d pads with spaces to two characters
       fprintf(stderr, "\r%2d", n);
       sleep(1);
}

---------- Post updated at 09:38 AM ---------- Previous update was at 09:29 AM ----------

Quote:
Originally Posted by bashuser2
Just a question in that though: Is there any C++(or even C) way of not calling this function all the time? (as the game will have many dialogues)Is there any way to tell the program that for everything printed in the program,you will use this function? A little bit difficult I think...
You could try overloading some functions in ostream for that, I suppose. I'm not sure you're given enough access to its internals to really affect the way the buffer is flushed, though. Theoretically these things are flexible like that. In practice...they're not.

I don't see what's so bad about calling a function. Are you really going to want to print everything like that, all the time? Or just dialogues? If you're thinking you want to avoid a million function calls like
print_dialogue("line1");
print_dialogue("line2");
print_dialogue("line3");
...

then it's time to abstract that some more, looping it somehow, or having the loop happen inside print_dialogue itself. An array of strings would work, and could be replaced by another backend like reading it from a file later.
This User Gave Thanks to Corona688 For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

mini digi-cam

hey guys! I am on a fedora core2 i686 with gui and I have a miniture cool-cam which is digital.. it connects through regular usb.. the system recognizes it and the when I go into the desktop peripheral and go to camera it gives name and tells test was successful.. it also says that the camera has... (0 Replies)
Discussion started by: moxxx68
0 Replies

2. Programming

Mini Shell in C

Hi Everyone, I am a student learning C and Unix. I want to create a shell in C which accepts command line arguments and executes them. I am not sure how to do this. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: passat
5 Replies

3. UNIX for Dummies Questions & Answers

mini distribution

Maybe someone knows floppy distribution with which I could connect to the internet and browse sites. THanks for answers (1 Reply)
Discussion started by: Vilmis
1 Replies

4. UNIX for Dummies Questions & Answers

mini shell programming (help)

Hi All, Well i m a taking an operating system course (newbie to unix) we have studied till now: the fork () execv() the teacher asked us to create a mini shell that execute a user command: cmd1 he said everything in is optional we can use any combination Well dudes , i m really... (2 Replies)
Discussion started by: ELECTRO
2 Replies

5. OS X (Apple)

Mac mini to Sony TV

Hi All, I have Mac mini, I bought DVI to HDMI cable and connected this to TV and sounds didn't come. On the Sony TV, right below VGA, I see mini-port plug in. I then connected VGA cable from Mac to Sony TV, I can see every thing. but for the sound, should I buy mini-port to mini-port cable.... (1 Reply)
Discussion started by: samnyc
1 Replies

6. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

7. Shell Programming and Scripting

Mini Project

Hi Experts, I'm a newbie.....just now i started to write some simple scripts on my own. Can anyone suggest me any simple project kind of stuff to hone my SHELL SCRIPTING skills....which involves database connection and more than that.....bcoz i already tried to write a script which connects to... (0 Replies)
Discussion started by: kritibalu
0 Replies

8. Shell Programming and Scripting

Need help in a mini project

Hi All, I want to make something like described below - "Double click on an executable file that will check the health status and other things of various linux servers and send an email to a list of people." I can make shell scripts for individual servers but how to make a script that will check... (1 Reply)
Discussion started by: csrohit
1 Replies
renpy(6)							       Games								  renpy(6)

NAME
renpy - engine for creating visual novels SYNOPSIS
renpy [path to the script directory] DESCRIPTION
Ren'Py is a programming language and runtime, intended to ease the creation of visual-novel type games. It contains features that make it easy to display thoughts, dialogue, and menus; to display images to the user; to write game logic; and to support the saving and loading of games. Ren'Py tries to be like an executable script, allowing you to get a working game without much more effort than is required to type the game script into the computer. Ren'Py is implemented on top of python, and that python heritage shows through in many places. Many Ren'Py statements allow python expres- sions to be used, and there are also Ren'Py statements that allow for the execution of arbitrary python code. Many of the less-used fea- tures of Ren'Py are exposed to the user by way of python. By only requiring use of the simplest features of python, it's hoped that Ren'Py will be usable by all game authors. USAGE
If you run the program without any arguments, zou will get an interactive launcher from where you can select, run and work different projects. For running a script, you need to give the full path to the directory that contains the game you want to play. For example: renpy /usr/share/games/renpy/demo/ To learn how to use the game interface, you should install and play renpy-demo. FILES
The game data for each user is stored at ~/.renpy/ directory. The scripts can be installed in the system bz placing them under /usr/share/games/renpy/ , but you can run any script in an arbitrarz directory just by telling the path as the parameter to the game. SEE ALSO
You can find more information at http://www.renpy.org/ May 2007 renpy(6)
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy