Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Akow), 1,365 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Everything but threading #338366
08/17/10 17:56
08/17/10 17:56
Joined: Feb 2006
Posts: 52
C
carlpa Offline OP
Junior Member
carlpa  Offline OP
Junior Member
C

Joined: Feb 2006
Posts: 52
I am continuing my work in reaction timers. I need most of my functions to run in sequence. I have run into a problem with
wait(1);
Each function has two or three
while(!key_any){wait(1);}
to allow subjects to read instructions and continue the task.
I have tried both wait_for() and proc_status directly without success.

I have succeeded with messy kludge coding. I am wondering if there is an elegant and general way to control multi-tasking.
Thank you.


Researcher & clinician. A6, A7, & A8
First computer a Commodore Pet
Re: Everything but threading [Re: carlpa] #338372
08/17/10 18:41
08/17/10 18:41
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
i don't know, where your problem is, but you should try this:
Code:
while(key_any) wait(1);     //Wait until no key is pressed
while(!key_any) wait(1);    //Wait until a key is pressed


If you write it like this, you can step through your code, but if you forget the first line, you get a break at the first line, but if you press any key, the code will run till its end


Visit my site: www.masterq32.de
Re: Everything but threading [Re: MasterQ32] #338395
08/17/10 20:32
08/17/10 20:32
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Can you show us some of the functions you are trying to get syncronised?

Ive got an idea on an external indexer, but I need to see some code
to figure a way to link it into your code....


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Everything but threading [Re: EvilSOB] #338402
08/17/10 22:11
08/17/10 22:11
Joined: Feb 2006
Posts: 52
C
carlpa Offline OP
Junior Member
carlpa  Offline OP
Junior Member
C

Joined: Feb 2006
Posts: 52
Thanks to all for their help.

I have tried
while(key_any){wait(1);}
while(!key_any) {wait(1);}

without success.

The complete code follows below (does not work):


#include <default.c>
#include <acknex.h>
#define PRAGMA_PATH "C:\Program Files(x86)\GStudio8\templates\images\"
///////////////////////////////
FONT* big = "Arial#128b";
FONT* medium = "Arial#32b";
BMAP* testbed = "aqua.tga";

var nstimuli = 10;
var practice = 0;
var section = 1; //0 = Simple 1 = Choice
var RT[210][2];
var test_data;

//var pass = 0; //to check on doing both tasks
var next = 0; //organize sequence

STRING* what ="#10";
STRING* first = "#40";
STRING* last = "#40";
STRING* age = "#10";
STRING* gender = "#5";
STRING* test_type = "#4"; ///0 for Simple 1 for Choice
STRING* numstim = "#4"; //Number of stimuli
STRING* pract = "#4"; //Number of PRACTICE stimuli

PANEL* test_bed =
{
pos_x = 0;
pos_y = 0;
layer = 0;
bmap = testbed;
flags = SHOW;
}

TEXT* test_txt =
{
pos_x = 400;
pos_y =250;
layer = 3;
font = big;
string (what);
flags = CENTER_X | CENTER_Y;;
}

TEXT* intro_txt =
{
pos_x = 10;
pos_y = 20;
layer = 2;
font = medium;
strings = 10;
}

TEXT* name =
{
pos_x = 20;
pos_y = 120;
layer = 2;
font = medium;
string (first, last, age, gender);
}

TEXT* parameters =
{
pos_x = 20;
pos_y = 120;
layer = 2;
font = medium;
string (test_type, numstim, pract);
}

function clear_intro()
{
var i;

for (i = 0; i < 10; i++) {str_cpy((intro_txt.pstring)[i], "");}
}

function results()
{
var i;
var avg = 0;
var terrors = 0;
var correct;
var holder;
STRING* str = "#15";
STRING* data = "#60";

if(next%2 >0){return;}
/// Set up output file////
str_for_num(data, sys_doy);
holder = sys_hours * 60;
holder += sys_minutes;
str_for_num(str, holder);
str_cat(data,"_");
str_cat(data,str);
str_cat(data,".txt");
test_data = file_open_write(data); ///filename is based on time

///subject name
str_cpy(data, last);
str_cat(data, " ");
str_cat(data, first);
str_cat(data, " ");
str_cat(data, gender);
str_cat(data,"\n");
file_str_write(test_data, data);

/////year
str_for_num(data,sys_year);
str_cat(data,"\n");
file_str_write(test_data,data);

///Test Type
if(section){str_cpy(data, "Choice\n");}
else{str_cpy(data, "Simple\n");}
file_str_write(test_data, data);

///means
for(i = practice ; i < nstimuli; i++)
{
if(RT[i][1] == 0){avg += RT[i][0];}
else { terrors ++;}

///Save the trial
str_for_num(data, RT[i][0]);
str_cat(data, ",");
str_for_num(str, RT[i][1]);
str_cat(data,str);
str_cat(data,"\n");
file_str_write(test_data, data);
}
holder = time_frame * 1000 / 16;
str_for_num(data, holder);
file_str_write(test_data, data);
file_close(test_data);
correct = nstimuli - terrors - practice;
if(correct > 0){avg = avg / (correct);}
if(section == 0) { str_cpy((intro_txt.pstring)[0], "Simple");}
else{str_cpy((intro_txt.pstring)[0], "Choice");}
set(intro_txt, SHOW);
str_for_num((intro_txt.pstring)[1], avg);
str_for_num((intro_txt.pstring)[2], terrors);
str_for_num((intro_txt.pstring)[3], holder);
if (next == 2)
{
str_cpy((intro_txt.pstring)[4], "Push Space to continue");
while(key_space == 0){wait(1);}
reset(intro_txt, SHOW);
}
if(next == 4) {str_cpy((intro_txt.pstring)[5], "Press F11 to exit.");}
}

function tester()
{
var running;
var t; //hold stimulus start time
var tt; // holds time of each trial
var tr = 0; //random factor between stimuli
var i; //counter
var stim; //stimulus number 1 - 3

if(next%2 == 0) {return;}
clear_intro();
str_upr(first);
str_upr(last);
str_cpy((intro_txt.pstring)[0], first);
str_cat((intro_txt.pstring)[0], " ");
str_cat((intro_txt.pstring)[0], last);
if (section == 0)
{
str_cpy((intro_txt.pstring)[1], "Please push cursor down key,");
str_cpy((intro_txt.pstring)[2], "When you see a large O on the screen.");
str_cpy((intro_txt.pstring)[4], "Press any key to begin.");
}
else
{
str_cpy((intro_txt.pstring)[1], "A 1, 2, or 3 will appear on the screen.");
str_cpy((intro_txt.pstring)[2], "When you see a 1, press the Arrow Left,");
str_cpy((intro_txt.pstring)[3], "When you see a 2, press the Arrow Down.");
str_cpy((intro_txt.pstring)[4], "When you see a 3, press the arrow Right,");
str_cpy((intro_txt.pstring)[5], "Press any key to begin.");
}
set(intro_txt, SHOW);
while(!key_any){wait(1);}
reset(intro_txt, SHOW);

set(test_txt, SHOW);
wait(-1); // wait a second
for (i = 0; i < nstimuli; i++)
{
running = 1;
t = total_ticks;
tt = t;
tr = 36 + integer(random(9));
stim = integer(random(3)) + 1;
str_for_num(what, stim); // Choice
if (section == 0){str_cpy(what, "O");} // Simple

while(running)
{

tt = total_ticks - t;
RT[i][1] = 0;

if (key_any)
{
running = 0;
RT[i][0] = tt* 1000/16;

if(section == 0){stim = 2;} // Simple
switch (stim)
{
case 1:
if(!key_cul){ RT[i][1] = 1;}
break;
case 2:
if(!key_cud){ RT[i][1] = 1;}
break;
case 3:
if(!key_cur){ RT[i][1] = 1;}
break;
}
}

if (tt > 32)
{
running = 0;
RT[i][0] = tt * 1000 / 16;
RT[i][1] = 1;
}
wait(1);
}
//End of stimulus test time
//Turn off stimulus
str_cpy(what, " ");
//Inter stimulus test time
while (tt < tr){tt = total_ticks - t; wait(1);} ///Wait for 2 sec between stimuli
}
next++;
}

function quit()
{
sys_exit(NULL);
}

function introduction()
{
var i = 0;
var a; //for checkling inputs


set(intro_txt, SHOW);
on_f11 = quit;
set(parameters, SHOW);

////Operator Instructions//////

str_cpy((intro_txt.pstring)[0], "This section is to enter the test parameters.");

//Enter num of stimuli
againC:
str_cpy(numstim, " ");
str_cpy((intro_txt.pstring)[1], "Please the number of stimuli.");
str_cpy((intro_txt.pstring)[2], "Please push enter when you are done.");
inkey(numstim);
nstimuli = str_to_num(numstim);
if((nstimuli <= 0) || (nstimuli > 200)) {goto againC;}

//Enter number of practice stimuli
againD:
str_cpy(pract, " ");
str_cpy((intro_txt.pstring)[1], "Please the number of PRACTICE stimuli.");
str_cpy((intro_txt.pstring)[2], "Please push enter when you are done.");
inkey(pract);
practice = str_to_num(pract);
if((practice <= 0) || (practice > 200)) {goto againD;}

nstimuli += practice;
str_cpy((intro_txt.pstring)[6], "Please push any key to continue to subject instructions.");

while(!key_any){ wait(1);}//Wait for keypress

reset(parameters, SHOW);
clear_intro();

/////Subject Instructions

str_cpy((intro_txt.pstring)[0], "Welcome to the Reaction Time Test.");
str_cpy((intro_txt.pstring)[1], "We appreciate your participation.");
str_cpy((intro_txt.pstring)[2], "DO NOT CONTINUE IF YOU HAVE");
str_cpy((intro_txt.pstring)[3], "ANY HISTORY OF SEIZURES OR EPILEPSY!");
str_cpy((intro_txt.pstring)[4], "Thank you and push any key to continue.");

while(!key_any){wait(1);}//Wait for keypress

///SUBJECT DATA

clear_intro();
str_cpy((intro_txt.pstring)[0], "Please type your first name.");
str_cpy((intro_txt.pstring)[1], "Please push enter when you are done.");
set(name, SHOW);
inkey(first);
str_cpy((intro_txt.pstring)[0], "Please type your last name.");
str_cpy((intro_txt.pstring)[1], "Please push enter when you are done.");
inkey(last);

againA: ///Entering age
str_cpy((intro_txt.pstring)[0], "Please type your age in years.");
str_cpy((intro_txt.pstring)[1], "Please push enter when you are done.");
inkey(age);
a = str_to_num(age);
if ((a <= 0) || (a > 95)) ///make sure it is a number > 0 and <95
{
str_cpy(age, " ");
goto againA;
}

againB: /// Entering gender
str_cpy((intro_txt.pstring)[0], "Please type m-key if male or f-key if female.");
str_cpy((intro_txt.pstring)[1], "Please push enter when you are done.");
inkey(gender);
str_upr(gender);
a = str_to_asc(gender);
if((a != 77) && ( a != 70)) //Not M or F
{
str_cpy(gender, " ");
goto againB;
}
str_for_asc(gender, a);

reset(name, SHOW);


/////GO TO TESTING//////

clear_intro();
reset(intro_txt, SHOW);
next++;
}


function main()
{

wait(5);
fps_max = 200;
random_seed(0);
section = integer(random(2));

if(next == 0) {introduction();}
wait_for(introduction);
if(next == 1) {tester();}
if(next == 2) {results();}

section = abs(section - 1);

if(next == 3) {tester();}
if(next == 4) {results();}

}


Researcher & clinician. A6, A7, & A8
First computer a Commodore Pet
Re: Everything but threading [Re: carlpa] #338576
08/19/10 10:15
08/19/10 10:15
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline
Serious User
Nidhogg  Offline
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Not sure if this will help you or not but I just saw this on the beta page proc_status(EVENT name) and proc_status2(EVENT name,ENTITY* ent) .

If not there is also info about wait_for(f) and wait_for_my(f) on the same page.


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Everything but threading [Re: Nidhogg] #338620
08/19/10 18:10
08/19/10 18:10
Joined: Feb 2006
Posts: 52
C
carlpa Offline OP
Junior Member
carlpa  Offline OP
Junior Member
C

Joined: Feb 2006
Posts: 52
Careful study of the program showed that the functions will cycle properly with a combination of:

while(key_any){wait(1);}
while (!key_any) {wait(1);}

with a

wait_for(...);

in the main function.
Thanks to all


Researcher & clinician. A6, A7, & A8
First computer a Commodore Pet

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