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 / [SOLVED] Why would my function not work correctly?

Author
Message
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 20th Apr 2023 22:53 Edited at: 20th Apr 2023 22:54
Everything works but the position, it positions everything in a row and not random like I ask.

So in the function when i say

random(800,1400),5,random(800,1500)

it places everything in uniform rows.

But when I position objects out of the function it places them randomly.

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Apr 2023 00:48 Edited at: 21st Apr 2023 00:51
you're only setting X#,Y#, Z# once via function parameter; set them in your for/next loop.

you may want to pass MinX#/MaxX#, et al, through parameters instead and then in your for/next do something like X# = Random(MinX#,MaxX#), etc.

otherwise, there is more code that you're not showing that could be the culprit.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Apr 2023 01:29 Edited at: 21st Apr 2023 01:30
Virtual Nomad

Well that didn't work either and I check all my code and nothing is using X# Y# Z# values.

this works but this is as far as it will let me do for positions.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Apr 2023 03:07 Edited at: 21st Apr 2023 03:08
that's pretty much what i was suggesting but what doesn't your 2nd function do for you? (at a glance it seems fine).

meanwhile, i updated this just for you (uses a standard 3d ray since i thought i saw you using that in another recent thread).

hope it helps.

note the storage of objects in an array which you don't seem to be doing above (and the note, there).
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Apr 2023 03:11 Edited at: 21st Apr 2023 03:12
Sorry, didn't see your post
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Apr 2023 04:00 Edited at: 21st Apr 2023 04:03
meanwhile, i updated this just for you (uses a standard 3d ray since i thought i saw you using that in another recent thread).

Thank you, Pretty much I am loading objects in game and after collecting them they delete, but my program freezes so i am forced to hide them.

I figured out how to cast a ray down to my water and that works now.

But I will look at your code and learn from it, thank you so much.

EDIT

I can not pass XYZ into the function. Just inside the function.

Here is my code that freezes my game.

ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 21st Apr 2023 11:35 Edited at: 21st Apr 2023 11:56
I don't know... but would you need to update stuff within your For / Next loop using Sync()

Or does that physics command need updating with Step3DPhysicsWorld(). Just a shot in the dark
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Apr 2023 12:00 Edited at: 21st Apr 2023 12:00
what are you doing with This2V3?

meanwhile, on hiding objects vs deleting them, when you delete a bullet object, you need to delete both the object and the physics body separately (both have the same id) or you will run into issues.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 21st Apr 2023 18:12 Edited at: 21st Apr 2023 18:15
This post has been marked by the post author as the answer.
While you're iterating through an arry ( list ) with for..next, you have to decrease your counter when deleting items in the loop, like:


Also, here's a simple method to do raycasts from from 2D mouse position into a 3D world. Just click on the spheres to delete them:


Hope that helps.

PSY


PSY LABS Games
Coders don't die, they just gosub without return
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Apr 2023 18:16 Edited at: 21st Apr 2023 18:18
Hi ando

I do sync and also Step3DPhysicsWorld() already and that is a must have. But thank you anyway.

Virtual Nomad

The This2V3 is for a vector 3 to hold position info for collision.

https://www.appgamekit.com/documentation-studio/Reference/Maths/CreateVector3.htm

I thought this could be crashing my game but I tried just checking collision with a ray but it still crashed so i keeping the vector 3, it works better.

Ok i will look into that and see if it works, I did delete the physics body and object at the same time so I will let you know.

Edit

PSY

I will try your idea for deleting objects thank you, I will update you if it works.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Apr 2023 18:35
Oh my lord this works and thank you so much PSY

PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 21st Apr 2023 20:05 Edited at: 21st Apr 2023 20:45
@Game_Code_here

You're welcome
I know the relief when you tinker with a code for hours and finally it works


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-11-23 08:25:22
Your offset time is: 2024-11-23 08:25:22