Scripts / Problem with Timing and Sprite Image

Author
Message
ozziedave
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location: Australia
Posted: 22nd Feb 2016 08:10
G' Day could a coding Guru include the correct code for timing the deletion, or hiding of a Sprite. I have tried every script example on the GG website, but cannot get the timer to work, had many screen freezes though.


-- Player Collecting The Golden Orb

gold_orb = 0
g_imgBackdrop = 0


function pick_gold_orb_init(e)
end

function pick_gold_orb_main(e)
PlayerDist = GetPlayerDistance(e)

if PlayerDist < 80 and g_PlayerHealth > 0 then
Prompt ("Press E To pick up Golden Orb")

if g_KeyPressE == 1 then
PromptDuration("Collected Golden Orb",6000)
PlaySound(e,0)
g_imgBackdrop = LoadImage("scriptbank\\images\\golden_globe\\ten.png")
g_sprBackdrop = CreateSprite( g_imgBackdrop )
SetSpritePosition( g_sprBackdrop,90,2 )
Prompt (gold_orb)
Collected(e)
Destroy(e)
gold_orb = gold_orb + 1
end
end

if gold_orb == 1 then
SetPlayerHealth(g_PlayerHealth+50)
PromptDuration("Collected Golden Orb - Health increased by 50 points - NEXT LEVEL ATTAINED",4000)
--I WANT TO DELETE OR HIDE THE GOLDEN GLOBE IMAGE AFTER 8 SECONDS HOW ?
end
end

Please could you try the code with your image to make sure it works ok, seems an impossible task.

Many Thanks
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 22nd Feb 2016 10:05 Edited at: 24th Feb 2016 09:55
Hi ozziedave

This should do what you want..
I just adapted your requirements to one of my existing pickup scripts.
It is working fine for me, but I am using the GG beta version, so let me know if you have any troubles..
As I don't have the current build anymore, to test this script on.

We don't have a hide sprite command yet, but.. they use the SetSpritePosition to position the sprite off screen, like this
SetSpritePosition( g_sprOrb[e],200,200 )

Cheers



Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
ozziedave
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location: Australia
Posted: 24th Feb 2016 04:56 Edited at: 24th Feb 2016 04:58
G' Day Perelect, thank you for your prompt reply, sorry but it didn't work, would not show "PromptDuration("Collected Golden Orb - Health increased by 50 points - NEXT LEVEL ATTAINED",4000)" , and on pressing 'E' anyway ,nothing showed up in the top right hand corner at all.

I tried moving code around a bit, but I could not make anything work at all. I am using The Christmas Beta and Windows 8.1, although it now shows V1.12, although it is still the Christmas Beta.

In other game makers it's a simple Wait(5).

Cheers
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 24th Feb 2016 09:48 Edited at: 24th Feb 2016 10:09
Hi ozziedave

lets try this..

1. Make sure the "pick_gold_orb.lua" script is within the scriptbank folder somewhere.
2. Just as a test, start a new blank map place a collectable down (say the packet of chips), and the start marker and nothing else.
3. Then run the map and see if you can collect it, your health should increase.
4. After that, stop test mode and go to the chips properties and assign the script that I wrote "pick_gold_orb.lua"
5. Make sure you have the image ten.png in the correct folder. scriptbank\\images\\golden_globe\\ten.png
6. Run it again, when you get close to the chip pack it should prompt "Press e To pick up", then press e then it should prompt ("Collected Golden Orb - Health increased by 50 points - NEXT LEVEL ATTAINED" and the image.

Doing it this way we are checking for any problems with the model and its fpe settings, that you are using for the orb.
If this works for you then we will look at the orb model you are using.

It should work, as I have now tested the script on my old laptop as well.

Maybe some else in the community could check if the script works for them. to verify.

I'm happy to keep helping you, so let me know how you go.

Cheers

a test image is attached
Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)

Attachments

Login to view attachments
ozziedave
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location: Australia
Posted: 25th Feb 2016 22:44
Hi Perelect, Tried the above ,still no image at top right corner or text shown. I can with the first post example(top of page) place an image at the top righthand corner of the screen, text shows up ok. The only problem is the darn Timer to delete the image after a period of time.

I guess I'll just have to look through all of the scripts on my hard drive to see if there is one I can convert to my own use.

Many thanks for your help though.
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 26th Feb 2016 00:06 Edited at: 26th Feb 2016 00:09
Try this I modified you original code with a heap of comments for you. This is working for me as well.
Interesting to see if this one works for you...

Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
ozziedave
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location: Australia
Posted: 26th Feb 2016 22:47
Hi perelect, Many thanks for your solid persistence with my problem code. You have come up with the answer for me.

-- Player Collecting The Golden Orb

local gold_orb = 0
local g_sprBackdrop = 0


function pick_gold_orb_init(e)
end

function pick_gold_orb_main(e)
PlayerDist = GetPlayerDistance(e)

g_imgBackdrop = 0

if PlayerDist < 80 and g_Entity[e]['collected'] == 0 and g_PlayerHealth > 0 then -- need to add a flag to stop the event from happening again
Prompt ("Press E To pick up Golden Orb")

if g_KeyPressE == 1 and g_Entity[e]['collected'] == 0 then -- need to add a flag to stop the event from happening again

gold_orb = gold_orb + 1

PromptDuration ("Collected Golden Orb. You now have "..gold_orb.." Goldern Orb's",5000)

PlaySound(e,0)
g_imgBackdrop = LoadImage("scriptbank\\images\\golden_globe\\ten.png")
g_sprBackdrop = CreateSprite( g_imgBackdrop )
SetSpritePosition( g_sprBackdrop,90,2 )
Collected(e) -- this changes the g_Entity[e]['collected'] = 0 flag, to g_Entity[e]['collected'] = 1
Hide(e)
CollisionOff(e)
SetPlayerHealth(g_PlayerHealth+50)
StartTimer(e) -- starts the timer at zero, if the timer is allready running it resets the timer back to zero
end
end

if g_Entity[e]['collected'] == 1 and GetTimer(e) > 6000 then -- if the item is collected and timer is greater than 8 seconds
PromptDuration("Health increased by 50 points - NEXT LEVEL ATTAINED",2000)
DeleteSprite ( g_sprBackdrop )
Destroy(e) -- destroying the entity
end
end

This is the finished code, mainly yours, this works well for me. Many thanks for your help.
PM

Login to post a reply

Server time is: 2024-05-03 11:33:19
Your offset time is: 2024-05-03 11:33:19