I got a bit carried away, and in my false excitement I deleted the first post, I apologize.
But, I am trying to call something that has the parameter const Event: TInputPressRelease within the update method. I can call something with the SecondsPassed parameter, but cannot figure out how to call the Event.
Hm, I’m not sure why you cannot call it. To solve this, I would need to see the source code, at least part of it, to tell what’s wrong.
To be clear,
-
There’s nothing special about calling routines (like methods) with
const Event: TInputPressReleaseparameter. You just pass this parameter. Note thatEventis a constant here, so you cannot pass it to something that expectsvar Sthg: TInputPressReleaseorout Sthg: TInputPressRelease(you would need to make a temporary copy for this purpose, but whether it makes sense – depends on what you try to do). -
The “events” in Pascal are just addresses of routines (methods or global routines). You call an event just as if you would call the method. We have some information about callbacks in Modern Object Pascal Introduction for Programmers | Castle Game Engine , see section “Callbacks (aka events, aka pointers to functions, aka procedural variables”.
-
But I’m probably already guessing too much
Please show the source code you have, then the problem will be clear.
if i use this, it returns
Error: Identifier not found "Event"
I am fairly certain I am my own issue here. I’m fairly good at being my own roadblock when it comes to anything programming.
Edit: I see the CurrentEvent there now and not event, i was trying a many different things to get it to work. Changing CurrentEvent: TInputPressRelease to Event: TInputPressRelease in the update variables works, but I’m still working on getting it to execute.
That said, I am incredibly sick and barely functioning at the moment so it may just be safe to ignore me for the time being, I came to a conclusion that I am just being overly stupid.
If you write your own method (PickAttack), you could change the amount and types of parameters as you wish.
For example you could just use
AIsMouseDown: Boolean; as parameter
and AIsMouseDown then as part of condition
PickAttack(buttonLeft in Container.MousePressed, SecondsPassed) when calling from Update method.
BTW, @michalis, maybe it would be more straightforward to provide same MousePressed check with [ ], as Pressed for keys ? without the need to use set semantics ? I could do such change and PR
that is exactly what I was looking for thank you so much.
I do think it would be much more straight forward to just have something like Container.MousePressed[buttonLeft]
To be clear, you got error Identifier not found "Event" because you literally did not have a value (like a variable) called Event at this point.
You had a value CurrentEvent. But even if you wanted to pass it, you would need to initialize it first. This makes sense only if you really want to create a “fake” event, you can use e.g. InputKey like CurrentEvent := InputKey(...).
I second the suggestion from @phomm to use buttonLeft in Container.MousePressed and take AIsMouseDown: Boolean . This makes sense, assuming that you want PickAttack to be part of Update, i.e. this will execute every frame, e.g. 60 times per second.
There are still bits I’m not sure about:
-
Why do you measure
SecondsusingTimerinPickAttack? This effectively measures the execution time of 2PlayAnimationcalls, but they should be instant and their execution speed should not affect anything. I’m confused why their execution speed determines whetherPlayerPickAxe1is hidden. -
Note that calling
PlayAnimationevery frame is likely not what you want, it will keep restaritng the animation if you callPlayAnimationeach frame with the same animation name. If you want to change the current animation, assignAutoAnimationinstead. But I’m unsure what you want to do here, so don’t apply my suggestion literally, rather check does everything inPickAttackmakes sense if you execute this method often.
Overall, I would recommend to double-check your logic around PickAttack.
- If this is something that is called from
Update, it happens ~60 times per second, you need to account for this – don’t perform actions that should be done once per user input. TakeSecondsPassedinto account. - On the other hand, if you want to execute
PickAttackon user input, then it needs a different logic. It should react to input (like fromPress), not be executed fromUpdate, not measure time passing.
You can read and experiment with sample in Designing user interface and handling events (press, update) within the view | Manual | Castle Game Engine . One must apply a different thinking for “things that happen once” and “things that need to be done constantly, in each Update” – I am not sure which one your PickAttack wants to be
You have to decide it, and make sure what it does matches the expectations.
I prefer a set in this case, as it allows for more functionality.
-
Though I agree it’s inconsistent with keys, where
Container.Pressed[keyX]is a boolean. -
As for length,
buttonLeft in Container.MousePressedis not much longer than
Container.MousePressed[buttonLeft]
-
The benefits when you have a set is that you can compare / pass it as a whole, e.g.
if Container.MousePressed <> [] then// check if any mouse button is pressed-
// check if any button from a defined set `RelevantButtons` are pressed RelevantButtons := [buttonLeft. buttonRight]; if Container.MousePressed * RelevantButtons <> [] then ..

