Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Nymphodora, Quad), 923 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with a for loop #468856
10/23/17 18:41
10/23/17 18:41
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
for(r=1;r<7;r++)
{
if(attacking_pwitch == r) //which witch?
{
for(s=1;s<13;s++)
{
if(attacking_pwitcht == s)//witchtype?
{
if(w_typempcurr[r] >= 2) //have enough magic
{
w_typempcurr[r] -= 2; //subtract magic
}
else
{
beep();
return;
}
}
}
}
}

okay. what I have is 6 witches on a board. these witches can be of 1 of 12 types(witchtype).

The 1st loop 'r' is finding the actual witch witch1 - witch6.
the 2nd loop 's' is finding the type of witch the first loop has found. when the witch and the witch type is found it checks to see if there is enough magic to perform the spell and subtracts that amount from the w_typempcurr, or the current amount of magic for this witch...

The problem I am having is that the for loop keeps selecting the first witch even though in a previous function, I specify which witch to select via another for loop. attacking_pwitch and attacking_pwitcht are global vars. "s" and "r" are local vars.

no matter which witch I click, the magic is always drawn from the 1st witch's bank. I have had this problem with several other for loops and thought it to be a timing issue, but even with placing wait(-1); before the function doesn't fix the issue.

I have considered writing it out the long way, but I wanted to know what I am doing wrong and see if I can fix it first.

it seems like it would be an easy fix, but I can't seem to figure it out.

note: I am using 1-7 and 1-13 for the for loops because the banks of magic and the witches are number 1-6 and 1-12.

thanks.


a8 commercial
Re: Help with a for loop [Re: seneca] #468858
10/23/17 19:54
10/23/17 19:54
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
since attacking_pwitch contains its index into the array, you can use it with no loops at all.

Code:
if(w_typempcurr[attacking_pwitch] >= 2) //have enough magic
{
  w_typempcurr[attacking_pwitch] -= 2; //subtract magic
}
else
{
  beep();
  return;
}


Re: Help with a for loop [Re: txesmi] #468859
10/23/17 20:10
10/23/17 20:10
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
seems simple enough.

I will give it a try.

thank you for the reply.


a8 commercial
Re: Help with a for loop [Re: seneca] #468860
10/23/17 20:39
10/23/17 20:39
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
I had to change a few things around in other parts of the code, but it worked like a charm!!!

Screw a for loop!!!

guess I made it more complicated than it needed to be.

Thank you very much!!!


a8 commercial
Re: Help with a for loop [Re: seneca] #468862
10/23/17 22:37
10/23/17 22:37
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
glad to be of help laugh


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