Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Newbie Questions
by AndrewAMD. 12/04/23 11:14
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (TipmyPip, izorro), 556 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
I hate while loops #137313
06/20/07 20:14
06/20/07 20:14
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
...because I can't get this particular function to work, and I don't think you can stop a while loop. So either this means that my AckNote project has come to a screeching halt that I can't get by, or there is some command in C-Script that I'm not aware of that can do this.

I've thought of proc_kill, but that won't do me good, as I don't want to write a pointer for every single panel that I use.

What I'm trying to do is write a few functions that redefine what the GUI colors are in themes. But at the same time, I want to make the colors customizable if none of the themes are desirable.

But, since my custom color function runs in a while loop, I cant do a thing about it.

Or can I?

(PS: I really hope I don't have to convert my entire project to Lite-C just to do this, as it has just over 650 lines of code.)




Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: I hate while loops [Re: MrCode] #137314
06/20/07 20:31
06/20/07 20:31
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
I didn´t understand what you need but maybe break; can help you?
If you call break from inside a while loop, to stop it and go on in the next parts of the function.
An alternative would be to give the while some more conditions:

var i;
while(i < 100) //use this
{
if(i < 100) //or
{
break; //this (I won´t do this...)
}
i += 1;
wait(1);
}

Quote:


(PS: I really hope I don't have to convert my entire project to Lite-C just to do this, as it has just over 650 lines of code.)




Sorry but in my opinion, the number of lines has nothing to say, because you can write the same script in one line wich can be written in several thousands of lines. Btw, my current project has about 2500 lines splitted into 6 or 7 files.
But this isn´t really much code there are projects with much more. I think the most importent is that the script is easy to understand and runs fast. Better to understand scripts are usually a bit longer than others because of comments and a lot of space.


Slin

Re: I hate while loops [Re: MrCode] #137315
06/20/07 20:34
06/20/07 20:34
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
RTFM:
-------------------------------------------------------
break

The instruction break between the winged brackets of a while loop will end the repetitions and continue with the first instruction after the closed bracket.
Example:
Code:

While (x < 100)
{
x+=1;
if(x == 50)
{
break; // loop will be ended prematurely
}
}


See also:

while, continue
--------------------------------------------------------
Your project can now continue


Our new web site:Westmarch Studios
Re: I hate while loops [Re: Slin] #137316
06/20/07 20:35
06/20/07 20:35
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
Yeap not sure what you mean either cause you dont give no code as example, but a while loop runs until its condition its true, then executes the rest of the function:

while(gui_redefine_top == 1)
{
...
wait(1);
}

Re: I hate while loops [Re: demiGod] #137317
06/20/07 21:00
06/20/07 21:00
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Thank's for the help, guys. I'm sorry if I was being a bit rude...

I have an idea: I'll define a _mode var (the underscore because mode is already a keyword), and then modify it when a particular function is executed, like this:

Code:

var _mode= a;

...

function mode_1_func()
{
_mode= a;
while(1)
{
...
if(_mode== b) || (_mode== c) || (_mode== d) || (_mode== e) || (_mode== f) || (_mode== g)
{
break;
}
wait(1);
}
}




Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: I hate while loops [Re: MrCode] #137318
06/20/07 21:03
06/20/07 21:03
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
I´d prefer this:

Code:

var _mode= a;

...

function mode_1_func()
{
_mode= a;
while((_mode== b) || (_mode== c) || (_mode== d) || (_mode== e) || (_mode== f) || (_mode== g))
{
...

wait(1);
}
}



Re: I hate while loops [Re: Slin] #137319
06/20/07 21:06
06/20/07 21:06
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
but you see, here's my code (it's kinda long, that's why I didn't give it in my first post):

Code:

function color_of_gui()
{
while(1)
{
gui.red= gui_colorred;
gui.green= gui_colorgreen;
gui.blue= gui_colorblue;
gui_dropdown.red= gui_colorred;
gui_dropdown.green= gui_colorgreen;
gui_dropdown.blue= gui_colorblue;
gui_dropdown2.red= gui_colorred;
gui_dropdown2.green= gui_colorgreen;
gui_dropdown2.blue= gui_colorblue;
gui_dropdown3.red= gui_colorred;
gui_dropdown3.green= gui_colorgreen;
gui_dropdown3.blue= gui_colorblue;
gui_dropdown4.red= gui_colorred;
gui_dropdown4.green= gui_colorgreen;
gui_dropdown4.blue= gui_colorblue;
quitter.red= gui_colorred;
quitter.green= gui_colorgreen;
quitter.blue= gui_colorblue;
gui_color.red= gui_colorred;
gui_color.green= gui_colorgreen;
gui_color.blue= gui_colorblue;
txt_color.red= gui_colorred;
txt_color.green= gui_colorgreen;
txt_color.blue= gui_colorblue;
gui_transparency.red= gui_colorred;
gui_transparency.green= gui_colorgreen;
gui_transparency.blue= gui_colorblue;
code_viewer.red= gui_colorred;
code_viewer.green= gui_colorgreen;
code_viewer.blue= gui_colorblue;
font_selector.red= gui_colorred;
font_selector.green= gui_colorgreen;
font_selector.blue= gui_colorblue;
tut_about.red= gui_colorred;
tut_about.green= gui_colorgreen;
tut_about.blue= gui_colorblue;
nofeature.red= gui_colorred;
nofeature.green= gui_colorgreen;
nofeature.blue= gui_colorblue;
about_acknote.red= gui_colorred;
about_acknote.green= gui_colorgreen;
about_acknote.blue= gui_colorblue;
preferences.red= gui_colorred;
preferences.green= gui_colorgreen;
preferences.blue= gui_colorblue;
wait(1);
}
}

function rainy_day_mode()
{
while(1)
{
gui.red= gui_colorred;
gui.green= gui_colorgreen;
gui.blue= gui_colorblue + 50;
gui_dropdown.red= gui_colorred;
gui_dropdown.green= gui_colorgreen;
gui_dropdown.blue= gui_colorblue + 50;
gui_dropdown2.red= gui_colorred;
gui_dropdown2.green= gui_colorgreen;
gui_dropdown2.blue= gui_colorblue + 50;
gui_dropdown3.red= gui_colorred;
gui_dropdown3.green= gui_colorgreen;
gui_dropdown3.blue= gui_colorblue + 50;
gui_dropdown4.red= gui_colorred;
gui_dropdown4.green= gui_colorgreen;
gui_dropdown4.blue= gui_colorblue + 50;
quitter.red= gui_colorred + 50;
quitter.green= gui_colorgreen + 50;
quitter.blue= gui_colorblue + 50;
gui_color.red= gui_colorred + 50;
gui_color.green= gui_colorgreen + 50;
gui_color.blue= gui_colorblue + 50;
txt_color.red= gui_colorred + 50;
txt_color.green= gui_colorgreen + 50;
txt_color.blue= gui_colorblue + 50;
gui_transparency.red= gui_colorred + 50;
gui_transparency.green= gui_colorgreen + 50;
gui_transparency.blue= gui_colorblue + 50;
code_viewer.red= gui_colorred + 50;
code_viewer.green= gui_colorgreen + 50;
code_viewer.blue= gui_colorblue + 50;
font_selector.red= gui_colorred + 50;
font_selector.green= gui_colorgreen + 50;
font_selector.blue= gui_colorblue + 50;
tut_about.red= gui_colorred + 50;
tut_about.green= gui_colorgreen + 50;
tut_about.blue= gui_colorblue + 50;
nofeature.red= gui_colorred + 50;
nofeature.green= gui_colorgreen + 50;
nofeature.blue= gui_colorblue + 50;
about_acknote.red= gui_colorred + 50;
about_acknote.green= gui_colorgreen + 50;
about_acknote.blue= gui_colorblue + 50;
preferences.red= gui_colorred + 50;
preferences.green= gui_colorgreen + 50;
preferences.blue= gui_colorblue + 50;
wait(1);
}
}



and what I want to be able to do is switch between them in a menu.

(btw, the frame rate isn't affected by the massive amount of changes per frame, at least on my computer.)

Last edited by MrCode; 06/20/07 21:10.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: I hate while loops [Re: MrCode] #137320
06/20/07 21:13
06/20/07 21:13
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Code:

var _mode = 0;
function color_of_gui()
{
_mode = 1;
while(_mode == 1)
{
gui.red= gui_colorred;
gui.green= gui_colorgreen;
gui.blue= gui_colorblue;
gui_dropdown.red= gui_colorred;
gui_dropdown.green= gui_colorgreen;
gui_dropdown.blue= gui_colorblue;
gui_dropdown2.red= gui_colorred;
gui_dropdown2.green= gui_colorgreen;
gui_dropdown2.blue= gui_colorblue;
gui_dropdown3.red= gui_colorred;
gui_dropdown3.green= gui_colorgreen;
gui_dropdown3.blue= gui_colorblue;
gui_dropdown4.red= gui_colorred;
gui_dropdown4.green= gui_colorgreen;
gui_dropdown4.blue= gui_colorblue;
quitter.red= gui_colorred;
quitter.green= gui_colorgreen;
quitter.blue= gui_colorblue;
gui_color.red= gui_colorred;
gui_color.green= gui_colorgreen;
gui_color.blue= gui_colorblue;
txt_color.red= gui_colorred;
txt_color.green= gui_colorgreen;
txt_color.blue= gui_colorblue;
gui_transparency.red= gui_colorred;
gui_transparency.green= gui_colorgreen;
gui_transparency.blue= gui_colorblue;
code_viewer.red= gui_colorred;
code_viewer.green= gui_colorgreen;
code_viewer.blue= gui_colorblue;
font_selector.red= gui_colorred;
font_selector.green= gui_colorgreen;
font_selector.blue= gui_colorblue;
tut_about.red= gui_colorred;
tut_about.green= gui_colorgreen;
tut_about.blue= gui_colorblue;
nofeature.red= gui_colorred;
nofeature.green= gui_colorgreen;
nofeature.blue= gui_colorblue;
about_acknote.red= gui_colorred;
about_acknote.green= gui_colorgreen;
about_acknote.blue= gui_colorblue;
preferences.red= gui_colorred;
preferences.green= gui_colorgreen;
preferences.blue= gui_colorblue;
wait(1);
}
}

function rainy_day_mode()
{
_mode = 2;
while(_mode == 2)
{
gui.red= gui_colorred;
gui.green= gui_colorgreen;
gui.blue= gui_colorblue + 50;
gui_dropdown.red= gui_colorred;
gui_dropdown.green= gui_colorgreen;
gui_dropdown.blue= gui_colorblue + 50;
gui_dropdown2.red= gui_colorred;
gui_dropdown2.green= gui_colorgreen;
gui_dropdown2.blue= gui_colorblue + 50;
gui_dropdown3.red= gui_colorred;
gui_dropdown3.green= gui_colorgreen;
gui_dropdown3.blue= gui_colorblue + 50;
gui_dropdown4.red= gui_colorred;
gui_dropdown4.green= gui_colorgreen;
gui_dropdown4.blue= gui_colorblue + 50;
quitter.red= gui_colorred + 50;
quitter.green= gui_colorgreen + 50;
quitter.blue= gui_colorblue + 50;
gui_color.red= gui_colorred + 50;
gui_color.green= gui_colorgreen + 50;
gui_color.blue= gui_colorblue + 50;
txt_color.red= gui_colorred + 50;
txt_color.green= gui_colorgreen + 50;
txt_color.blue= gui_colorblue + 50;
gui_transparency.red= gui_colorred + 50;
gui_transparency.green= gui_colorgreen + 50;
gui_transparency.blue= gui_colorblue + 50;
code_viewer.red= gui_colorred + 50;
code_viewer.green= gui_colorgreen + 50;
code_viewer.blue= gui_colorblue + 50;
font_selector.red= gui_colorred + 50;
font_selector.green= gui_colorgreen + 50;
font_selector.blue= gui_colorblue + 50;
tut_about.red= gui_colorred + 50;
tut_about.green= gui_colorgreen + 50;
tut_about.blue= gui_colorblue + 50;
nofeature.red= gui_colorred + 50;
nofeature.green= gui_colorgreen + 50;
nofeature.blue= gui_colorblue + 50;
about_acknote.red= gui_colorred + 50;
about_acknote.green= gui_colorgreen + 50;
about_acknote.blue= gui_colorblue + 50;
preferences.red= gui_colorred + 50;
preferences.green= gui_colorgreen + 50;
preferences.blue= gui_colorblue + 50;
wait(1);
}
}



If you want to switch between the functions, you just have to call it.

Re: I hate while loops [Re: Slin] #137321
06/20/07 21:14
06/20/07 21:14
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
oh,

Thanks!


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: I hate while loops [Re: MrCode] #137322
06/21/07 04:39
06/21/07 04:39
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Perhaps, you should have tried using an array of handles to panel pointers and maybe pan_create.

The following is hypothetical only.
Something similiar should work in principle.
Code:

panel* p1;
var uiPCount = 15; // panel count?
var uiColorDim = 3; // num color components?
var uiThemeOffset = 45; // panel count * color components?
var uiThemeCt = 100; // number of themes?
var uiColors[4500]; // 100 themes * panel count * color components?
var uiTheme = 0; // current ui theme?

// themes
define themeDefault = 0;
define themeRainy = 1;
define themeMrCodeRoxor = 2;

/*******************************
pfColor1
*******************************/
function pfColor1(_p1, &_color, _add) {
p1 = _p1;
p1.red = _color[0] + _add;
p1.green = _color[1] + _add;
p1.blue = _color[2] + _add;
}
/*******************************
pfColor2
*******************************/
function pfColor2(_p1, _add) {
pfColor1(_p1, vector(gui_colorred, gui_colorgreen, gui_colorblue), _add);
}
/*******************************
pfColor3
*******************************/
function pfColor3(_p1, _offset);
pfColor2(_p1, colors[uiThemeOffset * uiTheme + _offset * uiColorDim + 0])
pfColor2(_p1, colors[uiThemeOffset * uiTheme + _offset * uiColorDim + 1]);
pfColor2(_p1, colors[uiThemeOffset * uiTheme + _offset * uiColorDim + 2]);
}
/*******************************
pfColor4
*******************************/
function uifTheme(_theme);
uiTheme = _theme;
var i; i = 0;
pfColor3(gui, i); i++;
pfColor3(gui_dropdown, i); i++;
pfColor3(gui_dropdown2, i); i++;
pfColor3(gui_dropdown3, i); i++;
pfColor3(gui_dropdown4, i); i++;
pfColor3(quitter, i); i++;
pfColor3(gui_color, i); i++;
pfColor3(txt_color, i); i++;
pfColor3(gui_transparency, i); i++;
pfColor3(code_viewer, i); i++;
pfColor3(font_selector, i); i++;
pfColor3(tut_about, i); i++;
pfColor3(nofeature, i); i++;
pfColor3(about_acknote, _colors, i); i++;
pfColor3(preferences, _colors, i); i++;
}
//...

uifTheme(themeDefault); // default colors
uifTheme(themeRainy); // rainy day colors
// etc...




Last edited by testDummy; 06/21/07 07:00.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1