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.

AppGameKit Classic Chat / compiler glitch in my opinion

Author
Message
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 12th Oct 2016 03:29 Edited at: 12th Oct 2016 03:40
ok so i love agk and stuff.... but dang!

i spent 6 hours trying to figure out why my program was crashing building new object meshes and discovered this.



turns out i was adding indexes to my models 3d data even when my 2nd condition was not met. Can this not be fixed?? im soo lucky i spotted it after i just started to delete code like crazy trying to trouble shoot.

anyways i did fix it.... had to pull out the : marker


painfull day!

does anyone else agree with me that the compiler should not have taken my second line of code out of my condition it was stored in? its clearly written inside (if....endif) statement
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Oct 2016 09:01
What happens if you put spaces around the colon? (i.e. vertcnt=vertcnt+4 : indcnt=indcnt+6)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Oct 2016 09:02
i hope you zip't it before so you can give paul to investigate.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Oct 2016 11:21
I agree with you entirely!
Unfortunately, Paul does not, he thinks this is the correct functionality.

I emailed him about it recently:
Quote: "Hey Paul,
Not one for the forum but it definitely needs your attention:
An IF/THEN followed by a colon executes the commands after the colon even if the condition fails.

Eg.

do
if 1=2 then print("1st Print"): print("2nd Print")
Print("3rd Print")
sync()
loop

That should just print "3rd Print" but it also prints "2nd Print""


And this was his reply:
Quote: "Unfortunately that is not a bug, : is now treated exactly as a new line would be treated, so
if 1=2 then print("1st Print"): print("2nd Print")
gets converted to
if 1=2 then print("1st Print")
print("2nd Print")
which is why the second line always gets run. You need to use an if/endif block if you want to put more than one command in the if statement"
AGK V2 user - Tier 1 (mostly)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Oct 2016 12:23
@Scraggle: That's a slightly different argument, and one in which I'd actually agree with Paul. You are using THEN followed by the command you want to conditionally execute, then you have a : to say you are moving on to the next command which has nothing to do with the IF THEN bit. I agree that it is like having a new-line.

However MOBiiUS has an IF...ENDIF, and everything in between should be conditional, INCLUDING lines seperated by colons instead of newlines, so I agree it looks like a bug.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 12th Oct 2016 13:18 Edited at: 12th Oct 2016 13:29
ya the fact that its coded like this.... i would think it shouldnt execute unless the condition was met since its clearly inside the if/ endif statement

if p>10
print("hello") : print("world")
endif

i would expect both to be executed only if the condition was met.


if i wanted to seperate it i would have written it like this

if p>10
print("hello")
else
print("world")
endif

I convert allot of my code back and forth from darkbasic and sometimes i miss small details such as a colon.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Oct 2016 13:26
; = semicolon
: = colon

#justsaying
AGK V2 user - Tier 1 (mostly)
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 12th Oct 2016 13:28 Edited at: 12th Oct 2016 14:27
lol ! thanks i guess i miss details like that too...


edit: ive been checking small code examples and odly it seems to be working correctly now. I need to dig further and see if it was doing this cause it was inside a function.

Edit:

Its even worse then i thought. Ill need to send paul my program because the code actualy works as its suppose to but after running it for a while it starts to leak executing that second line without the other.

Ill try to pull it out but its a bad one....
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 12th Oct 2016 19:46
When this gets totally nailed down, I think a few sentences describing the bullet-proof usage syntax should be inserted in the Help Files.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Oct 2016 20:31
for my understanding
if 1=2 then print("1st Print"): print("2nd Print")

the endif is the line break not the command delimiter
the compiler should see this
if 1=2 then print("1st Print"): print("2nd Print"):endif

but i remember we already discuss this kind how if then works in agk.

instead it see this?
if 1=2 then print("1st Print"):endif: print("2nd Print")

maybe we can get it optional to use the endif self as must have for a if then statement.


AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 12th Oct 2016 21:32
The process of converting : into new line characters happens fairly early in the parsing process, so by the time it is decoding the if statement it no longer knows that you had them on the same line. Also it looks for a "then" meaning one statement, or "endif" meaning multiple statements, so you can't use both in the same block.

I tested a small example similar to the original but it worked as expected

nothing was printed to the screen.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Oct 2016 00:06 Edited at: 13th Oct 2016 00:07
edit: double post
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Oct 2016 00:07
ya sorry bout this post....

what was crashing on my computer yesterday does not seem to be crashing today? ... very odd. I must have done something else besides removing the Colin. I thought for sure that was the issue i was having.

no bug i guess..... no more error.... ? one of those coding days....
ill make sure i investigate much further before posting a bug again.
sorry paul.... sorry guys
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Oct 2016 00:31 Edited at: 13th Oct 2016 00:37
@paul
Quote: "The process of converting : into new line characters happens fairly early in the parsing process"


--------------
if 1=2 then print("1st Print"): print("2nd Print")
gets converted to
if 1=2 then print("1st Print")
print("2nd Print")
----------
maybe if the pre compiler add a endif to the end of row if "then" is used it will convert it to this
if 1=2 then print("1st Print"): print("2nd Print"):endif
gets converted to
if 1=2 then print("1st Print")
print("2nd Print")
endif

you will have the correct endif.
its much better for a basic dialect and often we can use 1 instead of three rows, will save screenspace.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Oct 2016 09:30
Quote: "maybe if the pre compiler add a endif to the end of row if "then" is used it will convert it to this"

No, usage of the THEN keyword makes the compiler treat the IF statement as a single statement, not a multiple line one. The conversion of the colon to a line break would be the correct and expected outcome.

In the example provided by SoftMotion3D, the uncommented example should work as expected, but the commented out code would not work as he expected as the statements all use the THEN keyword.

See the below:
Quote: "if tile_up<2
vertcnt = vertcnt + 4 : indcnt = indcnt + 6
endif"

vertcnt & indcnt only gets incremented if tile_up is greater than 2.

Quote: "If tile_down =< 1 then vertcnt = vertcnt + 4 : indcnt = indcnt + 6"

vertcnt gets incremented if tile_down is less than or equal to 1. indcnt always gets incremented as the IF statement is converted to the following:


To execute both statements within the one IF statement, do the following:
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Oct 2016 09:57
Quote: "No, usage of the THEN keyword makes the compiler treat the IF statement as a single statement"

the pre compiler was not a self made thing from tgc?
i believe it converts the basic syntax into c++.
paul said if the : replaced by new line, then it happens that only one command behind the "then" is interpreted.

basic conform is if you not using "endif" it is the end of row behind the "then" . should be the achievement somehow in my opinion.




AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Oct 2016 10:43
Meh.

I like it the way it is. Please don't change it as it could mean hours of re-writing code.

The documentation correctly describes it as :"When an if statement is followed by the then keyword then only the next statement is affected."... it doesn't say all statements to the end of the line.

@SoftMotion: Hopefully it was just a temoporary chair to keyboard interface error
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Oct 2016 10:50
Quote: "basic conform is if you not using "endif" it is the end of row behind the "then" . should be the achievement somehow in my opinion."

I disagree, this is normal behavior with all basic languages I've used.

Quote: "Please don't change it as it could mean hours of re-writing code."

This is also a factor.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 13th Oct 2016 11:42 Edited at: 13th Oct 2016 11:43
Although I agree this should remain as it currently is. VB does actually allow you to have multiple statements after 'Then'.

Reference: https://msdn.microsoft.com/en-us/library/752y8abs.aspx

Right at the bottom it states;

The following example illustrates the use of the single-line syntax.



Just saying
Using AppGameKit V2 Tier 1
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Oct 2016 13:22 Edited at: 13th Oct 2016 13:22
i think its fine the way it is also.... im just use to writting for darkbasic where a stack of commands behind a conditional statement executes only if the condition was met on the same line.

i came to the conclusion it was the colin because my model data i was saving out was ending with 4-6 more indexes without any vertex data to go with them. It was not happening all the time however.... im sure it was something else that was triggering the false data to increase. It may have been just a coincidence that i removed the colin the same time as adjusting something else.

oh well.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Oct 2016 15:29 Edited at: 13th Oct 2016 15:29
This is a colon
:

This is a Colin


#couldn'tresist
AGK V2 user - Tier 1 (mostly)

Attachments

Login to view attachments
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Oct 2016 16:34
Haha... Yes that is and i had to remove him to fix my game lol
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Oct 2016 17:33
Quote: ""Please don't change it as it could mean hours of re-writing code.""

i agree, but optional will be ok.

AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Oct 2016 18:59 Edited at: 13th Oct 2016 19:00
Quote: "I disagree, this is normal behavior with all basic languages I've used."

typical usage in c64 basic, i found this at c64 basic wiki website.
IF A=64 AND B=64 THEN PRINT " !!! BINGO !!!": GOTO 58

a normal row, thats why endif is the end of row.
if bla=1 then x=x+1:y=y+1 else x=x-1:y=y-1

as Funnell7 wrote vb6 the most common used basic at pc was same.

blitzbasic 3d at pc
If 1=0 Then Print("A") : Print("B")
If 1=1 Then Print("C") : Print("D")
will print C&D
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Oct 2016 10:48
GW Basic also allows multiple colon sepearted commands following an IF...THEN. However, all versions of BASIC have their own quirks, and really isn't a big deal as long as you know the syntax of the version you are using... plus those other versions are all old. Languages evolve.

And this is a Semi Colin:


V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Oct 2016 16:01
CQTS*






*Chuckles Quietly To Self - The new, more realistic version of LOL. I wonder if it will catch on
AGK V2 user - Tier 1 (mostly)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Oct 2016 08:56
Quote: " all versions of BASIC have their own quirks, and really isn't a big deal as long as you know the syntax of the version you are using"

yes, but it would be fine if we can use a full row at screen with commands (optional). the current systax will always be a trap.


AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 15th Oct 2016 10:03
I don't like it at all!
Computer programs are supposed to be logical but there is nothing logical about this.

I understand where Paul is coming from and there has to be a need to separate colon delimited lines but I think any colon delimited statements after a THEN should all have the equivalent of an ENDIF placed after them before the compiler kicks in.

So this:


should be interpreted as this:


And if that change means that some people have to rewrite some of their code, it will at least teach them to code more logically
AGK V2 user - Tier 1 (mostly)
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Oct 2016 15:10
Honestly I've run into quirky behavior with : all the way back through DBC. I don't trust em and always use a full if endif


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 17th Oct 2016 13:39
I'm not going to change the way this works, there may be a lot of apps that already rely on the existing functionality.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Oct 2016 16:56
@paul
Quote: "there may be a lot of apps that already rely on the existing functionality."

my dark thoughts are something like #allow_if_then_statements
just a nice to have feature if you have deadly boredom. he he.

CLOSED

AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Oct 2016 09:12
Quote: "just a nice to have feature if you have deadly boredom. he he."

I'd rather bug get fixed.
The current implementation is logical to me.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 18th Oct 2016 09:52
Quote: "is logical to me."

i think its equal to have exact one condition between if ... then
but we can combine it, just the cumulative result have relevance.
so myself see this horizontal:
if ... then ... else ... endif
and same as vertical:
if
...
then
...
else
...
endif

everything in "..." is a block of code with a command delimiter.

Quote: "I'd rather bug get fixed."

yes, all in priority.

AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Login to post a reply

Server time is: 2024-11-25 01:42:10
Your offset time is: 2024-11-25 01:42:10