Works One Way But Not The Other

Community Forums/Monkey Talk/Works One Way But Not The Other

dw817(Posted 2016) [#1]
I know Monkey-X is relatively new. Still, I'm running into some rather strange problems and limitations.

I have a file called, "Scroll Rectangle" which looks like this:



Pretty simple, right ? Well, if I try to compile it with the filename of, "Scroll Rectangle.monkey" I get this compilation error.

../main.cpp:4586:22: error: expected initializer before 'Rectangle_xa'
extern int bb_Scroll Rectangle_xa;
^
../main.cpp: In member function 'virtual int c_nano::p_OnRender()':
../main.cpp:4708:29: error: 'bb_Scroll' was not declared in this scope
bb_graphics_DrawRect(Float(bb_Scroll Rectangle_xa),FLOAT(0.0),FLOAT(50.0),FLOAT(50.0));
^
../main.cpp:4710:12: error: expected ';' before 'Rectangle_xa'
bb_Scroll Rectangle_xa+=1;
^
../main.cpp: At global scope:
../main.cpp:6434:15: error: expected initializer before 'Rectangle_xa'
int bb_Scroll Rectangle_xa;
^
../main.cpp: In function 'int bbInit()':
../main.cpp:6479:2: error: 'bb_Scroll' was not declared in this scope
bb_Scroll Rectangle_xa=0;
^
../main.cpp:6479:12: error: expected ';' before 'Rectangle_xa'
bb_Scroll Rectangle_xa=0;
^
Makefile:55: recipe for target 'build/Debug/main.o' failed
mingw32-make: *** [build/Debug/main.o] Error 1
TRANS FAILED: Error executing 'mingw32-make CCOPTS=" -O0" OUT="Debug/MonkeyGame"', return code=2

Quite a bit. Now, if I COPY that exact code and don't change a thing and save it as a new file, say, "test.monkey" and then try to compile it, it works fine.

What's going on here - and how do I fix it ?

Also, when I compile to a HTML5 game, doesn't matter if it's DEBUG or or RELEASE, it badly staggers in the browser. The rectangle speeds up, slows down, hesitates, and hiccups. It doesn't do this in "Desktop Game (Glfw2)" or "Desktop Game (Glfw3)."

I understand Monkey-X is a commercial program ATM, is anyone else having these problems and inconsistencies ?


therevills(Posted 2016) [#2]
Rename the file to: ScrollRectangle.monkey (no spaces) - I would raise a bug, you shouldnt be able to use a file with spaces in it.

Also you should be separating your logic from the render.

Import mojo

Class Nano Extends App
  Field xa:Float
  
  Method OnCreate()
    SetUpdateRate 60
  End

  Method OnUpdate()
    xa += 1
  End

  Method OnRender()
    Cls(50, 100, 150)
    SetColor(255, 255, 255)
    DrawRect(xa, 0, 50, 50)
  End
End

Function Main()
  New Nano()
End



dw817(Posted 2016) [#3]
Well, the creepy thing is, it =DID= work for about 2 executions - the filename, then died with that nasty error. I would investigate if you think it's a SPACE. Thanks for the answer tho.

What about the staggering in HTML5, do you (or anyone else) receive that ? If I'm gonna plonk $100 cash down on this lingo I wanna make sure it's at least as smooth as BlitzMAX.


therevills(Posted 2016) [#4]
With HTML5 you've got to be careful, it depends on the browser. I always recommend Chrome to get the best out of it. And be careful with Set Color...


dw817(Posted 2016) [#5]
I've seen some talk of FLASH. Can Monkey-X be easily ported to Flash ? I remember writing 2-projects for NewGrounds which were FLASH. That alone would be worth Monkey-X with its good programming language.

And - what exactly is Ignition ? A graphics library ?


therevills(Posted 2016) [#6]
Yes, Monkey-X does output to Flash (although I wouldnt target Flash, Flash is dead).

It currently supports the following targets:
* HTML5
* Flash
* Windows (GLFW)
* Mac OSX (GLFW)
* iOS
* Android
* MS Phone 8

MX2 will only support C++ targets:
* Windows
* Mac
* iOS
* Android
* Emscripten (Web)

Ignition is a cool games framework (Mojo 1), similar to to Diddy (Mojo 1), Pyro (Mojo 2) fantomEngine (Mojo 1), Fantom-X (Mojo 2) and Flixel (Mojo 1).


therevills(Posted 2016) [#7]
I've raised a bug request for you here:

http://www.monkey-x.com/Community/posts.php?topic=10326

The issue is that Monkey-X converts your global variable by add a prefix "bb_<filename>_" so it goes from "xa" to "bb_Scroll Rectangle_xa" which has a space in it.


dw817(Posted 2016) [#8]
Thanks, well if Flash isn't the big output medium, for both PC and Cellphones, what is, Therevills ?


therevills(Posted 2016) [#9]
HTML5.... And native...

Apple doesn't support Flash on iOS and I think recently that Google has also stopped supporting it too.


Matty(Posted 2016) [#10]
Google stopped supporting flash for android in about 2012 and Apple refused to ever support it.

While html5 is cross platform there are still issues with audio.

My opinion is that native is best but requires more work to get right.

Edit: and reading your error log above it is quite apparent the space is causing that issue...you can see it is expecting a newline ";" marker where the space is that suggests it is confused about the space...treating the two words as separate statements.

Re:stuttering html5 - I would imagine it is something either in your code or a browser issue. Browsers can still be inconsistent in their behaviour when there are errors in your code as some rowsers ignore javascript errors while others experiences random effects due to programming errors. Edit - by programming errors i mean your errors not the browser manufacturer.


dw817(Posted 2016) [#11]
The game I saw was written in Monkey-X (according to the author) but I don't know what it was written in (port), and it didn't stagger remotely.

Let me find the game:

http://www.newgrounds.com/portal/view/668625

Now as for my rectangle or any other program I've brought into Monkey-X, this is the first time I have seen ANY program stagger in any window in any browser.

You can blame the browser I suppose, which doesn't make sense considering the game written above was Written in Monkey-X - or - maybe there is a better way to code a scrolling rectangle ?

Or is it possible the commercial version doesn't have this staggering problem ?

The thing is, ANY code I've tried in Monkey-X that exports to HTML5 (not just my own code but others) staggers. I can check with Chrome, but - what about Firefox users, plentiful that there are ?

Check that game above, no staggering at all. What was it written in ? That would be the reason for me to want to program in Monkey-X, stable and smooth graphics.


dw817(Posted 2016) [#12]
Also, need to add. I'm doing a little investigation, HTML5 is Javascript ? I have javascript turned off, I know my friend Chris has never turned it on. He said that was a great way for viruses to get in the computer.

I'm not blaming Monkey-X in the least for this, but I suspect a lot of other people have Javascript turned off as well, definitely cutting down on the base of people who use or play Monkey-X runtimes written in HTML5.


Matty(Posted 2016) [#13]
HTML5 is javascript yes....you won't get anything all happening if javascript is truly turned off...javascript and HTML5 are effectively the same thing.

While not wanting to put you off monkey - javascript is a very easy language to code in if you merely want to target html5/browsers.

Most monkey code won't stagger. I'd say there is something in the code that is being used that does it.

As I said - some browsers handle errors in code differently. For example, an array out of bounds error will be ignored by some browsers while others have been known to show unusual effects (such as stuttering). That is why I said it is likely a coding error in the games you have seen the stuttering in.


Matty(Posted 2016) [#14]
Oh...googling gave me this:

- Browser statistics on JavaScript disabled.
- Why we should support users with no JavaScript (it's update with some 2014 stats). Hope it helps. Generally, the statistics vary but it looks like nearly 1% of users have JS disabled (globally talked).Nov 18, 2014
Is there any recent data on the number or percentage of ...
https://www.quora.com/Is-there-any-recent-data-on-the-number-or-percent...


.....so it's not a huge number.....anyone who wants to play a HTML5 game will have javascript enabled because HTML5 is javascript.


therevills(Posted 2016) [#15]
Getting a virus from JS inside a browser is very very rare...

Anyway, as Matty has stated if you have JS disabled you should not be able to view anything when running the code for the HTML5.

Did you try running my version of the code with the "logic" in the OnUpdate method?


dw817(Posted 2016) [#16]
Matty:

Quora says page not found. Well, let's start at the top then.

Can SOMEONE please code the above example (or recode entirely) where it does not stagger.

It just needs to be a rectangle that scrolls across the screen from left to right. That's all.

Therevills, I tried your code. It helps a 'tiny' bit. I still get staggering. Can I ask then, is that game above.

Also, is there a way of running Glfw3 Online from a browser, bypassing HTML5 completely ?

http://www.newgrounds.com/portal/view/668625

Further, that game I mentioned above, is that Javascript or something else ? It does run very smoothly.

. . .

Tried out the rectangle code in Google Chrome. At first it staggers badly. Then I rerun it, and it is very smooth indeed.


Matty(Posted 2016) [#17]
No access to desktop right now but these are some simple html5 games ive written that hopefully are smooth on your pc. The full source is availablw within and the first one effectively has a scrolling rectangle so maybe it will help.

http://mattiesgames.com/fullmooncombat/

http://mattiesgames.com/wizarena/

http://mattiesgames.com/gorgoth/

Edit....so the moment i post the links my host decides to have problems....come back in 5 minutes.


therevills(Posted 2016) [#18]
Try using delta timing to get it smoother. Also are you running MX from DropBox or similar folder? I've found that running from those folders can slow down the apps till the files have synced.


Blitzplotter(Posted 2016) [#19]
OK, I'm still quite new to Monkey, I'm on mobile so cannot try your example. I've found making sure you put as much as possible within the Oncreate method, keeping the onRender method as succinct as possible eliminates stutters in HTML 5 targets. My 5p.

Try putting the xa+1 into the onUpdate?


Blitzplotter(Posted 2016) [#20]
OK, I'm still quite new to Monkey, I'm on mobile so cannot try your example. I've found making sure you put as much as possible within the Oncreate method, keeping the onRender method as succinct as possible eliminates stutters in HTML 5 targets. My 5p.

Try putting the xa+1 into the onUpdate?

Sorry, double post..


therevills(Posted 2016) [#21]
Try this, it uses a delta timer:

Strict

Import mojo

Function Main:Int()
	New MyApp()
	Return 0
End

Class MyApp Extends App
	Const FPS:Int = 60
	Field x:Float, y:Float
	Field delta:DeltaTimer
	
	Method OnCreate:Int()
		delta = New DeltaTimer(FPS)
		SetUpdateRate(FPS)
		x = 0
		y = 100
		Return 0
	End
	
	Method OnUpdate:Int()
		delta.UpdateDelta()
		x += 1 * delta.delta
		If x > DeviceWidth() Then x = 0
		Return 0
	End
	
	Method OnRender:Int()
		FPSCounter.Update()
		Cls
		FPSCounter.Draw(0, 0)
		DrawRect(x - 5, y - 5, 10, 10)
		Return 0
	End
End

'summary: Simple Frames per second counter
Class FPSCounter Abstract
	Global fpsCount:Int
	Global startTime:Int
	Global totalFPS:Int

	Function Update:Void()
		If Millisecs() - startTime >= 1000
			totalFPS = fpsCount
			fpsCount = 0
			startTime = Millisecs()
		Else
			fpsCount+=1
		End
	End

	Function Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)
		DrawText("FPS: " + totalFPS, x, y, ax, ay)
	End
End

'summary: DeltaTimer by James Boyd
Class DeltaTimer
	Field targetfps:Float = 60
	Field currentticks:Float
	Field lastticks:Float
	Field frametime:Float
	Field delta:Float
	
	Method New (fps:Float)
		targetfps = fps
		lastticks = Millisecs()
	End
	
	Method UpdateDelta:Void()
		currentticks = Millisecs()
		frametime = currentticks - lastticks
		delta = frametime / (1000.0 / targetfps)
		If delta > 5 Then
			delta = 1
		End
		lastticks = currentticks
	End
End



Blitzplotter(Posted 2016) [#22]
@therevills - nice piece of code there ;)


Derron(Posted 2016) [#23]

Method OnUpdate:Int()
delta.UpdateDelta()
x += 1 * delta.delta
If x > DeviceWidth() Then x = 0
Return 0
End



so you wrap when x is 1.yy pixels farther than the last visible pixel on the screen?
First Pixel is at 0, last Pixel is at DeviceWidth()-1 (or is this different in Monkey?)

Think it should be "If x >= DeviceWidth() Then x = 0".



@"staggering"
When coding "Apes Banana Conquest" in Monkey, I recognized that I could not get it to run similar smooth as in BlitzMax. The Reason is, that objects are rendered on integer positions at the canvas. In BlitzMax you could render them at fractions (making them a bit "blurry"). Especially for slow objects these "integer grids" are visible on low-dpi-screens (big screen, low resolution). The object seems to "jump" pixel by pixel.
If your object moves very fast the eye is lazy enough to make the movement a bit more smooth.

Now the GC might kick in and this then lead to "hickups" (entity moves with non-linear speed). Together with the "integer grid" this might lead to a bit noisy movements.
Normally I would say you would add Tweening to DeltaTiming but this imho won't work well with that "integer grid".


Is there a way to render at fractions on a HTML-Canvas with Monkey?


bye
Ron


dw817(Posted 2016) [#24]
Still a lot of hiccups in Firefox. Does anyone else get staggering for that last code by Therevills ? This is why I would be interested in FLASH as it has NEVER staggered under any browser - none that I was aware of anyways.

Now was it you or someone else that mentioned Monkey-X can be ported to FLASH ?

Matty, I tried your first game, it hiccups too. The bad news is, I DOUBT my browser is the only one.

Matty, could you post your game in Flash so I could see that ? I suspect that would fix all problems - or if there is some other compilation output for Internet browsers ?

Monkey-X is undoubtedly a great language, it still just has a few bugs to work out.


Blitzplotter(Posted 2016) [#25]
@thervills - code works a charm within my firefox browser, no stuttering - sweet!


dw817(Posted 2016) [#26]
Well bully for you, Blitz. *Grin* Something is causing the staggering however, and it won't just be me that has it.

It's actually pretty good that it does stagger - so I (and the developers) can see that some bug needs to be worked out.


therevills(Posted 2016) [#27]
So you dont have Javascript disabled?

Do you have any browser plugins installed and whats your PC specs?


Blitzplotter(Posted 2016) [#28]
@dw817, just for your info, I developed a similar 'move a square' piece of code which uses data which has been parsed from a Global Positioning Satellite training device (a native tcx file) and then moves the square around within the browser tracking the path that was taken whilst jogging with my dog in the 'real' world.

Now, I did experience some 'staggering' within my code at first, but that was because I'd all the data parsing and manpulation for display within the onRender function. When I moved it into the onCreate function the issue vanished. I'm still really new to Monkey, well, I confess I've had it a couple of years but my day job stole my coding 'mojo' ;) for a couple of years until the last few weeks.

http://www.blitzbasic.com/Community/posts.php?topic=105592

Hope you get to the bottom of your issue soon *grins*


Danilo(Posted 2016) [#29]
@dw817:
Try using rlKmAN's WebGL target. It's the plain HTML5 target, modified to use WebGL instead.
Copy it to the MonkeyX target folder and then choose the HTML5 WebGL target in the IDE.
Might be better because of hardware acceleration.


dw817(Posted 2016) [#30]
BlitzPlotter:

Don't worry, I have my laser-trained satellite to hone in on the signal. Better wear some sunscreen before you step out tonight. :)

Danilo, took me a-while to get that stuffed into the right directory. It does clean-up a lot of the staggering, it's still there, but passable now.

Strange it seems to be a smaller square, different resolution ? How do you set for resolution ?

Alslo can you please let me know what all target platforms are available with purchased version of Monkey-X ? IE, Javascript, Flash, etc.


Danilo(Posted 2016) [#31]
All Targets are listed at the Shop page.


dw817(Posted 2016) [#32]
Yep, there's Flash. Has anyone made a Flash program today that can be seen Online from Monkey-X ?

I was reading the comments of one of the author's who provided a "banana," the Champagne Glass generated from dots. He said:

'Flash version performs really well even and easyly does 20000 dots.
'HTML5 version seems to be approximately 20 times slower and lags on more than 1000 dots.


And what exactly is GLFW2 and GLFW3, Danilo ? What hardware platforms do they cover ?


Danilo(Posted 2016) [#33]
GLFW is used for the Desktop targets, and it is hardware-accelerated using OpenGL.


dw817(Posted 2016) [#34]
By desktop do you mean solely Windows ?


Danilo(Posted 2016) [#35]
Desktop means usually 'Win, Linux, Mac' in the MonkeyX world.

I used MX on Windows some time ago, and it used GLFW.
Now I'm using Mac OS X, and MX uses GLFW there as well.
Don't need Linux, but I think it's the same there.


dw817(Posted 2016) [#36]
Okay, now let's check on some things, Danilo. With Monkey-X you can indeed write games, programs, whatever. But to put them Online ? If it's a single file, like Flash, sure you can do that easily.

But I don't think Monkey-X has the ability of BlitzMAX's INCBIN, where it can embed media and data directly in its runtime.

So suppose I have written a massive game in Monkey-X with over 100 or even 1000 external data files, how would it get distributed where it could be played Online ?


Matty(Posted 2016) [#37]
If you were going to play a game in a browser you don't want 100s or 1000s of external data files since over http each file accessed will cause a delay....for example if you have 1000 sprites you are better combining them into as few files as possible as the time taken from a web connection to download 1 large file is much smaller than 1000 small files.

If you want to play a game on a browser with Monkey X and it is html5 with lots of data files then you would host it on your webspace with the appropriate file structure.

You won't write a massive game that runs in a browser - not unless you are happy with long load times - in any language.


dw817(Posted 2016) [#38]
Actually this is something I had planned for a system I was working on. The data is MASSIVE but saved in one easy-to-byte file. I think I'm beginning to see why the classic RPG Maker isn't an Online affair yet, not if they have approx. 862 external files per game, even the commercially compiled ones.

Does Monkey-X have an INCBIN ability ?

As far as hosting, that would definitely cost money - I can't think of any website where you can upload anything for free except text and pictures. This once again goes back to FLASH as the whole kit & kaboodle can be stored in one file, and a streaming loading one at that.

I know that as I've written a few FLASH programs. Really quite nice, the first part loads, you get to see the loader pull in the rest and you can play some simple mini-games while you're waiting.

Danilo, that last adjustment to Monkey-X is a good one - but is there a way to change the resolution ? I tested and for GLFW2 and GLFW3 the resolution is 640x480, in the browser - I'm not sure.

Trying some 'bananas' I see they are in the corner of the screen, apparently also blind as to what the dimensions of the media screen are.


Danilo(Posted 2016) [#39]
@dw817:
For GLFW you can change the Window size using SetDeviceWindow().

For HTML5 you need to use some JavaScript. See the following examples (save all 3 files in the same directory):

canvasFunctions.js


test1.monkey


test2.monkey


Another way for fixed size HTML5 canvas:
Just change the target directly (or better a copy of the target). Open "MonkeyX/targets/html5/template/MonkeyGame.html" and change the part:
var CANVAS_WIDTH=640;
var CANVAS_HEIGHT=480;


For more informations, especially about Flash, you should probably better ask in the MonkeyX forum.


Blitzplotter(Posted 2016) [#40]
@dw817, you need to up the power on the laser, I was struggling not to slip on the ice on a jog yesterday morning ;) GPS co-ords incoming - I reckon I might have a snowy jog unless you can up your laser power to death ray standards ;)


dw817(Posted 2016) [#41]
Blitzplotter, here, I've managed to hack in to the configuration of the Hubble Telescope and removed the safety on the laser spotter.

So now instead of it taking pictures it shoots a laser beam anywhere on the planet at 6000k. You better run fast now. *Grin*

Back on subject, I am talking with someone who has commercial Monkey-X and am getting information about how smooth a Flash compilation will run - but they too are saying even in the version they purchased, it staggers for them.

Now, if Monkey-X could guarantee and execute raw source code from BlitzMAX, ANY code, and have the same stability and smoothness, we could be talking a great deal here !


therevills(Posted 2016) [#42]
There is the BlitzMax Target for Monkey... but it hasnt been updated for a while...

http://code.google.com/p/monkey-max/source/list

http://www.monkey-x.com/Community/posts.php?topic=4806


dw817(Posted 2016) [#43]
Running into another problem, I have this program I was writing to test the keyboard:



And while in the browser the arrow keys work, it does not for either Glfw2 or Glfw3 ?

Danilo, what if I'm on a website that doesn't allow upload of Javascript, only Flash ?


dw817(Posted 2016) [#44]
Wh - where did Simon Armstrong's post go in this thread ??




therevills(Posted 2016) [#45]
Try this:




dw817(Posted 2016) [#46]
Awright ! You got it to work both in GLFW and the Internet browser !

Should point out that in GLFW, you cannot use the arrow keys from the NUMBER KEYPAD to move the rectangle - only the main arrow keys, but in the browser edition (Firefox v43.0.4) you can use either.

I'm not sure if that's a bug or a feature ! :D


therevills(Posted 2016) [#47]
Some targets are more picky, for consistency you need to keep you main App class in that format. So that you have an OnCreate method (and use SetUpdateRate), OnUpdate (do all your logic here) and OnRender (do all your drawing here).


dw817(Posted 2016) [#48]
Ratz ... I was hoping to get away with the lot of it just in OnRender(). Still, for consistency shouldn't compiling from one platform to the other to be transparent ? That is, the results are exactly the same no matter what ?

And, did anyone ever post a FLASH example of any Monkey-X program I can see in activity Online or the *.SWF for download ?


skidracer(Posted 2016) [#49]
Here is a monkey game I wrote running in Flash

http://www.newgrounds.com/portal/view/555446

Flash remains the best way to get your game noticed by casual gamers, even though it has been dead for a couple of years nothing comes close.


therevills(Posted 2016) [#50]
Still, for consistency shouldn't compiling from one platform to the other to be transparent ? That is, the results are exactly the same no matter what ?


In a perfect world, yeah :)

I was hoping to get away with the lot of it just in OnRender()


It so much better keeping your update logic away from your rendering.


dw817(Posted 2016) [#51]
Hi Simon. That is one AWESOME game you wrote ! :D

I want to really talk with you about how you made it, did you have to use any external files or is all the media (pictures & audio) internal to the program ?

Does it save any external files - and if so - how do you retrieve them later ?


skidracer(Posted 2016) [#52]
Flash embeds all files. At the time I had to modify monkey as it was pre-release but Mark added embedding as standard to Flash not long after. Portals still pay for flash games and expect them to be site-locked and encrypted so you still need to invest some time in learning the platform specifics.


Blitzplotter(Posted 2016) [#53]
Simon, that is by far one of the most captivating games I've played online within a browser..... ever. The cry of 'YEEEeeeeeee harrrr' is great.

@dw817, if I post the GPS co-ords of my latest run, any chance you can up the power of your laser so there isn't any ice on the roads I'm running on ;) - and I like your fish story !


dw817(Posted 2016) [#54]
Yeah, I wrote two flash programs myself. But I used the Macromedia system - it was a royal pain in the butt. One was a tutorial on Flash written in Flash, got some nice comments on that one.

The other was an attempt at making moving objects, my Kaleidoscope with some music, and as it had a glass effect to the bars, that was well received too.

Now Simon, you have to be able to save files, right ? Like High-Scores and stuff. How is that handled in Monkey-X ? You can't just save on their servers, right ? Did you have to foot for your own and pay monthly ?

BlitzPlotter. Let me see here. This is a reflective lens that works from the sun. It can melt a penny.
https://www.youtube.com/watch?v=jrje73EyKag

And - glad you liked my story ! Some people were rather insulted by it I think. :)


Blitzplotter(Posted 2016) [#55]
Melting a stack of pennies is pretty impressive, boiling water in seconds - now that has something going for it that could help the environment - instead of boiling a kettle you could boil a bottle - might need to be quite a thick bottle though!

Yeah,loading/saving from a server is something I've been 'toying' with, however I'd need to design databases and everything and its kinda exceeing my 'hobbyist' requirements and kinda delving into something a full blown company might do, you never know though - we'll see how long my coding mojo continues ;)

Have set up a server or two for forums now and then, but even that was a bit headachey.


dw817(Posted 2016) [#56]
Yeah, see, that's my problem. What do I really wish for ? I wish I may I wish I might ... well, anyways, I would LIKE to be able to make an Online RPG Maker or Game Maker, that uses my code and gives everyone a chance to save all their work Online - or, to be able to do one click and SAVE it RECALL it for later.

That's talking quite a bit of code that would somehow access storage Online, and ... that's outside my understanding.

Now today I can post data Online myself and recall it easily in my programs, but that's not the same thing.