Log In  


Cart #sogahugasu-0 | 2024-10-09 | Code ▽ | Embed ▽ | No License


hey everyone, having some trouble.
im trying to make it so that when you collect the emerald a bit into the first level, it prints "gem get!" next to it.
however, when I collect it, nothing happens.
i would also like the text to disappear after a few seconds. how would I do that?

the emerald code is in tab 5 under function upickups2(). apologies if any of the code is difficult to read, I'm pretty new to this.

also, any further feedback for the game is much appreciated!

(please don't mind the door sprites at the beginning of the level, its just for debug purposes so that I can test level 2 quickly!)



your code "works" but the text is only shown on the single frame where you get the gem. At the time you get the gem, you need to store somewhere the X,Y and text you want to display, plus the expritation time of the message (time()+2 for a 2 seconds message for example).
Somewhere in _draw, you need to loop over your messages to display. If it has expired, the message is to be removed from the list of texts to display. Otherwise it should be printed.


RealShadomCaster I sort of understand? so i need to store the values in _draw, and then add a time function for the text... but how do I do those things, I'm new


Let's start simple : our text will be some kind of visual representation of what the player said. So you grab the gem, a little "gem get!" is shown for a second where the gem used to be before vanishing, but if say you hit a spike during that second, the message will be replaced by the new "ouch" message near the spikes.

When we get the gem, we add the text message info to the player :

player.message={x=304,y=13,color=0,expire=time()+1,text="gem get!"}

in draw_game() let's deal with the message if any :

if (player.message) then
 -- the player has a message
 if(time()>player.message.expire) then
  --delete the expired message
  player.message=nil
 else
  -- display the valid message
  print(player.message.text,player.message.x,player.message.y,player.message.color)
 end
end

function upickups2()
--- ---
 print("gem get!",304,13,0)
--- ---
end

print() is being executed in the _update()->update_game() thread.
It should be executed in _draw()->draw_game().


Cart #bigebitito-0 | 2024-10-09 | Code ▽ | Embed ▽ | No License


i think i inserted it correctly, i understand what you wrote (apparently not), but there is no text?


shiftalow, how would i make it exectute in _draw? i trid moving upickups2() to draw_game() and nothing happened when I went onto the gem.


My reply was advice about your first cart, so don't worry about it anymore.

Next we'll deal with the cart you posted. Do not put a message object into the player object in init_game().

Instead, write it in the process where you acquire the emerald.

function upickups2()
 if pu2.act then
  if abs(player.x-pu2.x)<16 and
     abs(player.y-pu.y)<15 then
--- ---
   player.message={x=304,y=13,color=0,expire=time()+1,text="gem get!"} -- code by RealShadowCaster
--- ---
  end
 end
end

For the time being, try executing the process to display the message in draw_game() somewhere that is not surrounded by if statements.
(If it's inside if abs(player.x)<95 then ... the display won't work properly.)

if abs(player.x)<95 then
 print("level 2",8,200,rnd(14))
end

if (player.message) then -- code by RealShadowCaster
 -- the player has a message
 --- ---
end

Modified cart


Cart #bigebitito_s-0 | 2024-10-09 | Code ▽ | Embed ▽ | No License



if (player.message) then -- code by RealShadowCaster
-- the player has a message


end

if message then what? I'm assuming the --- --- is meant to be something, but what would it be a placeholder for


--- --- are omitted lines. (The way they are expressed may vary depending on who writes them.)

The unabridged code is below.

if (player.message) then
 -- the player has a message
 if(time()>player.message.expire) then
  --delete the expired message
  player.message=nil
 else
  -- display the valid message
  print(player.message.text,player.message.x,player.message.y,player.message.color)
 end
end

Cart #dopuyohiri-0 | 2024-10-09 | Code ▽ | Embed ▽ | No License


Here's the cart with the code previously provided in the correct places :

at start, in init_game the player has no message to display, so there was nothing to change there.

When you get the gem, in function upickups2, that's where you need to add the message to the player.

And the displaying of the message happens in _draw, more precisely, in draw_game after displaying the player


that worked, thanks so much!



[Please log in to post a comment]