Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / If nested inside elseif

Author
Message
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 4th Jun 2017 20:09
I believe I have mistaken nested ifs inside of elseifs.

For example:

if i=0
blah
elseif i =1
if o=1
other blah
endif
elseif....

I believe I was wrong in thinking the nested if broke out of the entire if statement? I thought once an elseif was correct it exited the if statement... so if i=1 it would do those commands and quit the entire thing.

I am testing something, and the bad result is so rare I don't get to see it much. I have corrected the code using if/else/endif, then I am back inside the elseif statement. Which, at the very least, does the same thing if it doesn't fix the problem.

My code is below I am getting a result I thought I coded as impossible, but I guess I coded wrong.

I am storing random values in 3 variables. I am trying to set rules to which random number I can get, as it determines the direction of a corridor.

My previous_last was a 3, then I randomed a 4(last), and then a 3 again(current). But I should not be able to get that result. You can see that on the first elseif.

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Jun 2017 00:28
Your first if, there is no scope for change, if last is 1 or 3 set current but you block current from being last (1 and 3) and also (2 and 4), so if last was 1 to start the only option left is 3, hence your result
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 6th Jun 2017 01:55
Very good. Man, I envy you smarties. I was able to figure this out.. well not really. I just deduced it after a failed dungeon attempt. But, man you were able to see it immediately in the code. That's so far beyond me... lol.

I have changed it to this, and have yet to see any overlapping rooms. 1 to 4 are the cardinal directions of the corridor if you were curious.

Login to post a reply

Server time is: 2024-11-22 07:07:21
Your offset time is: 2024-11-22 07:07:21